Thanks to visit codestin.com
Credit goes to github.com

Skip to content

ALIAS_STANDARD_FUNCTION_NAMES doesn't work correctly #67

@KKoovalsky

Description

@KKoovalsky

When setting the option ALIAS_STANDARD_FUNCTION_NAMES to ON only the definitions inside printf.c will be affected. Inside printf.c https://github.com/eyalroz/printf/blob/develop/src/printf/printf.c#L54:

#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

But in the printf.h there is no include "printf_config.h", thus the declarations will never be aliased.

It means that, if the option is set to ON and the library is compiled, installed and consumed:

#include "printf.h"

int main()
{
    char c[64]; 
    snprintf(c, sizeof(c), "%d %f", 5, 160.1);

    return 0;
}

One gets compilation error:

main.cpp: In function ‘int main()’:
main.cpp:6:12: error: ‘snprintf’ was not declared in this scope
6 | snprintf(c, sizeof(c), "%d %f", 5, 160.1);
| ^~~~~~~~

Possible solutions:

  1. Install printf_config.h along with printf.h and put #include "printf.h" at the top of printf.h.
  2. Generate printf.h and rename the function names basing on the ALIAS_STANDARD_FUNCTION_NAMES option value.
  3. Generate printf.h by putting PRINTF_ALIAS_STANDARD_FUNCTION_NAMES macro dynamically at the top of the printf.h file during installation and use target_compile_definitions(printf PUBLIC PRINTF_ALIAS_STANDARD_FUNCTION_NAMES) for the build interface.
  4. Other?

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions