I am writing a C program that is expected to be compiled with all major compilers. Currently I am developing on GCC on a linux machine and will compile on MSVC before committing the code. To make the cross-compiling easy, I am compiling with -ansi
and -pedantic
flags. This worked well until I started using snprintf
which is not available in C89 standard. GCC can compile this without the -ansi
switch but MSVC will fail always as it doesn't have C99 support.
So I did something like,
#ifdef WIN32
#define snprintf sprintf_s
#endif
This works well because snprintf
and sprintf_s
has same signatures. I am wondering is this the correct approach?
Any help would be appreciated.