Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Alias preprocessor define is working? #54

Closed
thestumbler opened this issue Nov 8, 2021 · 5 comments
Closed

Alias preprocessor define is working? #54

thestumbler opened this issue Nov 8, 2021 · 5 comments
Assignees
Labels
bug Something isn't working regression A feature or aspect which worked properly in the past, no longer does

Comments

@thestumbler
Copy link

I tried to use the alias function names define, and as best I can tell it didn't do anything. Looking at the code, it isn't clear to me how it's supposed to work. I am on the latest 27 Sep commit.

#ifdef PRINTF_ALIAS_STANDARD_FUNCTION_NAMES
# define printf_    printf_
# define sprintf_   sprintf_
# define vsprintf_  vsprintf_
# define snprintf_  snprintf_
# define vsnprintf_ vsnprintf_
# define vprintf_   vprintf_
#endif

// ... some stuff here ...

#ifdef PRINTF_ALIAS_STANDARD_FUNCTION_NAMES
# undef printf_
# undef sprintf_
# undef vsprintf_
# undef snprintf_
# undef vsnprintf_
# undef vprintf_
#endif

I temporarily hand-edited my local printf.h file and went back to way function name aliasing worked in the previous 17 Aug commit. This works, and I understand why it works (unlike the current commit).

#ifdef PRINTF_ALIAS_STANDARD_FUNCTION_NAMES
# define printf    printf_
# define sprintf   sprintf_
# define vsprintf  vsprintf_
# define snprintf  snprintf_
# define vsnprintf vsnprintf_
# define vprintf   vprintf_
#endif

// ... some stuff here ...

I did read the issue #14 notes, but they didn't explain what I'm experiencing. Regarding the 27 Sep commit, am I missing something about how to make it work and/or understanding how it should work?

Thanks,
-Chris

@eyalroz
Copy link
Owner

eyalroz commented Nov 8, 2021

I did mess that up. Working on it.

eyalroz added a commit that referenced this issue Nov 8, 2021
…14. Added a test for whether aliasing works, in which the standard library function names are used, without including the `<stdio.h>` or any other standard library headers.
@eyalroz
Copy link
Owner

eyalroz commented Nov 11, 2021

@thestumbler : Can you please try it again now?

@eyalroz eyalroz self-assigned this Nov 11, 2021
@eyalroz eyalroz added bug Something isn't working regression A feature or aspect which worked properly in the past, no longer does labels Nov 11, 2021
@thestumbler
Copy link
Author

I just tested it, the latest commit on the develop branch. No joy.
First of all , my compiler (gnu arm-none-eabi-g++ v 6.3.1 Atmel build for Atmel/Microchip SAM-E5x chip) doesn't like the preprocessor #if statement without a conditional (the second line from the snippet below)

#ifdef PRINTF_ALIAS_STANDARD_FUNCTION_NAMES
#if PRINTF_ALIAS_STANDARD_FUNCTION_NAMES
# define printf_    printf
# define sprintf_   sprintf
# define vsprintf_  vsprintf
# define snprintf_  snprintf
# define vsnprintf_ vsnprintf
# define vprintf_   vprintf
#endif
#endif

Even when commenting this out in all three places (twice in the h file and once in the c file), it doesn't actually work.
I got it to work by basically putting it back like before:

(1) swapped all of the definitions around at the top of the header file, e.g...

WAS: # define printf_    printf
 IS: # define printf    printf_

(2) removed the #undef block at the end of the header file, and removed the duplicate? block at the top of the c file.

@thestumbler
Copy link
Author

"commenting this out in all three places..." I mean like this:

#ifdef PRINTF_ALIAS_STANDARD_FUNCTION_NAMES
//#if PRINTF_ALIAS_STANDARD_FUNCTION_NAMES
# define printf_    printf
# define sprintf_   sprintf
# define vsprintf_  vsprintf
# define snprintf_  snprintf
# define vsnprintf_ vsnprintf
# define vprintf_   vprintf//
//#endif
#endif

@eyalroz
Copy link
Owner

eyalroz commented Nov 12, 2021

First of all , my compiler (gnu arm-none-eabi-g++ v 6.3.1 Atmel build for Atmel/Microchip SAM-E5x chip) doesn't like the preprocessor #if statement without a conditional (the second line from the snippet below)

Ok, I'll change it to

#ifndef PRINTF_ALIAS_STANDARD_FUNCTION_NAMES
#define PRINTF_ALIAS_STANDARD_FUNCTION_NAMES 0
#endif

Even when commenting this out in all three places (twice in the h file and once in the c file), it doesn't actually work. I got it to work by basically putting it back like before:

The thing is, I can't do that. We can't go around replacing print's in people's source code, outside the library, with printf_. Those replacements will happen in comments, in C++ namespaces... can't have that. The macros must be undefined at the end of the header.

eyalroz added a commit that referenced this issue Nov 12, 2021
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working regression A feature or aspect which worked properly in the past, no longer does
Projects
None yet
Development

No branches or pull requests

2 participants