P
Pedro Graca
#include <stdio.h>
#ifdef C99
#define FMT_STRING "The value is %zu.\n"
#define CAST_SIZE_T
#else
#define FMT_STRING "The value is %lu.\n"
#define CAST_SIZE_T (unsigned long)
#endif
int main(void) {
size_t val=42;
printf(FMT_STRING, CAST_SIZE_T val);
return 0;
}
I don't even know for sure if the C99 macro is defined in my
implementation ... but the code compiled and run without glitches with
gcc
gcc -W -Wall -std=c89 -pedantic c9099.c -oc90
gcc -W -Wall -std=c99 -pedantic c9099.c -oc99
My questions are:
a) Is there a standard way to identify the standard being used to
compile the program (the "C99" predefined macro?)?
b) Is the way I used #ifdef usual accepted practice to code for the two
standards?
#ifdef C99
#define FMT_STRING "The value is %zu.\n"
#define CAST_SIZE_T
#else
#define FMT_STRING "The value is %lu.\n"
#define CAST_SIZE_T (unsigned long)
#endif
int main(void) {
size_t val=42;
printf(FMT_STRING, CAST_SIZE_T val);
return 0;
}
I don't even know for sure if the C99 macro is defined in my
implementation ... but the code compiled and run without glitches with
gcc
gcc -W -Wall -std=c89 -pedantic c9099.c -oc90
gcc -W -Wall -std=c99 -pedantic c9099.c -oc99
My questions are:
a) Is there a standard way to identify the standard being used to
compile the program (the "C99" predefined macro?)?
b) Is the way I used #ifdef usual accepted practice to code for the two
standards?