"Vladimir S. Oka" <> writes:
> wrote:
>> In C89 standard, the snprintf function is NOT included in <stdio.h>...
>>
>> Thus, using snprintf in your code and compiling with gcc -ansi leads to
>> the following warning:
>>
>> warning: implicit declaration of function `snprintf'"
>>
>> In order to nicely get rid of this bad stuff, I intended to do
>> something like:
>>
>> #if WE_ARE_COMPILING_USING_ANSI_C89_RULES
>> int snprintf(char *str, size_t size, const char *format, ...);
>> #endif
>>
>> Which is defining the prototype of the function in case stdio.h won't
>> do it.
>>
>> Question is : is there a symbolic constant
>> WE_ARE_COMPILING_USING_ANSI_C89_RULES defined by gcc, or do I have to
>> make it up myself, and how ?
>
> The Standard specifies that a macro by the name:
>
> __STDC_VERSION__ /* two `_`s front, and back) */
>
> should be defined an for C90 it should be:
>
> 199901L
But be careful. A conforming C90 implementation isn't allowed to
provide a function called snprintf() in <stdio.h>, but an
implementation might provide it as an extension (e.g., if it conforms
only partially to C99).
What you really want to do (I think) is use the implementation's
snprintf() if it exists, perhaps only in a non-conforming mode.
There's no standard macro that will tell you that. An
auto-configuration system that checks directly whether snprintf is
supported might be worthwhile.
--
Keith Thompson (The_Other_Keith)
kst- <http://www.ghoti.net/~kst>
San Diego Supercomputer Center <*> <http://users.sdsc.edu/~kst>
We must do something. This is something. Therefore, we must do this.