質問

I want to conditionally use either printf() or a statement:

#define USE_PRINTF

#ifdef USE_PRINTF
#define macrofn(str) printf(str)
#else
#define macrofn(str) some_statement
#ifndef USE_PRINTF

But I'm getting the following error:

incompatible implicit declaration of built-in function 'printf'

What am I doing wrong? Thanks

役に立ちましたか?

解決

You don't necessarily have to include the <stdio.h> before the macro definition. What you really need is #endif for the #if you have started. For example, the following programme will work all fine:

#define USE

#ifdef USE
#define asd printf("asd")
#else
#define asd puts("kek")
#endif

#include<stdio.h>

int main( ) {
    asd;
    getchar( );
    return 0;
}

So... yeah.

他のヒント

You need to add #include <stdio.h> to your file.

Take a look here for more information about this error message.

You need to include stdio.h if you want to use printf.

You should use this syntax:

#include <stdio.h>

#define USE_PRINTF

#ifdef USE_PRINTF
#define macrofn(str) printf(str)
#else
#define macrofn(str) some_statement
#endif
ライセンス: CC-BY-SA帰属
所属していません StackOverflow
scroll top