473,320 Members | 2,094 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,320 software developers and data experts.

is there a symbolic constant telling us we are using a C89 compiler?

Hi all!

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 ?
thanx
(please, I m quite a newbie, so maybe I got totally wrong)

Feb 7 '06 #1
7 1905
ju*****@gmail.com wrote:
Hi all!

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

There was a discussion about this recently in c.l.c so look it up as
well.

PS
There should also be __STDC__ defined as 1 if implementation is
conforming. Look in section 6.10.8 of the Standard.

--
BR, Vladimir

Feb 7 '06 #2

"Vladimir S. Oka" <no****@btopenworld.com> wrote in message
news:11*********************@f14g2000cwb.googlegro ups.com...
ju*****@gmail.com wrote:
Hi all!

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

There was a discussion about this recently in c.l.c so look it up as
well.


Which google is very good at ... here's a start:

http://groups.google.com/group/comp....t=0&scoring=d&


Feb 7 '06 #3
"Vladimir S. Oka" <no****@btopenworld.com> writes:
ju*****@gmail.com 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) ks***@mib.org <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.
Feb 7 '06 #4
On 2006-02-07, ju*****@gmail.com <ju*****@gmail.com> wrote:
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
What if your library really doesn't provide snprintf? This won't make
the link error go away.
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 ?
__STDC_VERSION__ < 199901L, but see above. [However, if you intend to
provide your own version of snprintf if it's not present, then you
should be fine.]
thanx
(please, I m quite a newbie, so maybe I got totally wrong)

Feb 7 '06 #5
On 2006-02-07, Keith Thompson <ks***@mib.org> wrote:
"Vladimir S. Oka" <no****@btopenworld.com> writes:
ju*****@gmail.com 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.


<offtopic>
Or there are tricks you can play with link order rules on some systems,
as I explained in an earlier thread about powf (another function that
was newly introduced with the c99 standard). See also your
implementation docs
Feb 7 '06 #6

"Vladimir S. Oka" <no****@btopenworld.com> wrote in message
news:11*********************@f14g2000cwb.googlegro ups.com...
ju*****@gmail.com wrote:
Hi all!

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 ?

In gcc, the -ansi option tells it not to define any names that pollute your
name space, such as snprintf. Since this is what you don't want, one option
is not to use the -ansi option. Then the prototype in the header will be
visible (assuming it's there, which is likely).

Alternatively, if you keep -ansi, it defines the macro __STRICT_ANSI__, so
you can #ifdef for that. It's non-standard, but it's not a sin to test
whether it's defined. (Commonly this macro is what is used in the header to
#ifdef out the snprintf prototype)


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


This value is for C99 surely. The macro wasn't in C90, it was added in 1994
--
RSH
Feb 8 '06 #7
Jordan Abel wrote:
On 2006-02-07, ju*****@gmail.com <ju*****@gmail.com> wrote:
...
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 ?


__STDC_VERSION__ < 199901L, ...


That's potentially unreliable since a C90 implementation can do...

#define __STDC_VERSION__ 19900101L

One alternative to using __STDC_VERSION__ is to check whether
SIZE_MAX is defined in <limits.h>.

--
Peter

Feb 8 '06 #8

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

20
by: CoolPint | last post by:
While I was reading about const_cast, I got curious and wanted to know if I could modify a constant variable through a pointer which has been "const_cast"ed. Since the pointer would be pointing to...
7
by: No Spam | last post by:
----snip #define POSITIVE_INTEGRATOR_SATURATION 0x03000000L // #define NEGATIVE_INTEGRATOR_SATURATION 0xFD000000L // long integrator; integrator=0;
2
by: Matthias Steinbart | last post by:
Hi there, I'm creating a class to be viewed in a property-grid control. I'm using the Browsable, Category, Description, etc. -Attributes to specify the display-behaviour of the class in the...
10
by: PB | last post by:
Hi ! I have the following code, which I am using in an Embedded systems, c-compiler.. However I see the same problem with GCC too.. I need the last 10 bits of an address pointer, which is...
6
by: fctk | last post by:
hello, i'm trying to compile this small program: int main(void) { unsigned long int max; max = 4000000000;
1
by: emin.martinian | last post by:
When trying to compile python extensions written in C using "python setup.py build" on cygwin I get the following error: foo.c: initializer element is not constant foo.c: error: (near...
1
by: amygrant1701 | last post by:
Hi, I've done this before so I don't see what I could doing wrong here. I'm running mysql 5x on freebsd. I'm using the default data directory of "/var/db/mysql" In there I have several dozen...
23
by: =?iso-8859-1?q?Santiago_Urue=F1a?= | last post by:
Hi, I tried to return a pointer to a constant string, but the compiler gives the following warning if a cast is not used: warning: assignment from incompatible pointer type This is the code:
1
by: sora | last post by:
Hi, I've developed a MFC program under VS 6.0. My debugger *was* working fine and I've used it often for my project. Then, one day, the errors below appear and they prevent me from using the...
0
by: ryjfgjl | last post by:
ExcelToDatabase: batch import excel into database automatically...
0
isladogs
by: isladogs | last post by:
The next Access Europe meeting will be on Wednesday 6 Mar 2024 starting at 18:00 UK time (6PM UTC) and finishing at about 19:15 (7.15PM). In this month's session, we are pleased to welcome back...
1
isladogs
by: isladogs | last post by:
The next Access Europe meeting will be on Wednesday 6 Mar 2024 starting at 18:00 UK time (6PM UTC) and finishing at about 19:15 (7.15PM). In this month's session, we are pleased to welcome back...
0
by: Vimpel783 | last post by:
Hello! Guys, I found this code on the Internet, but I need to modify it a little. It works well, the problem is this: Data is sent from only one cell, in this case B5, but it is necessary that data...
0
by: jfyes | last post by:
As a hardware engineer, after seeing that CEIWEI recently released a new tool for Modbus RTU Over TCP/UDP filtering and monitoring, I actively went to its official website to take a look. It turned...
0
by: ArrayDB | last post by:
The error message I've encountered is; ERROR:root:Error generating model response: exception: access violation writing 0x0000000000005140, which seems to be indicative of an access violation...
1
by: PapaRatzi | last post by:
Hello, I am teaching myself MS Access forms design and Visual Basic. I've created a table to capture a list of Top 30 singles and forms to capture new entries. The final step is a form (unbound)...
1
by: CloudSolutions | last post by:
Introduction: For many beginners and individual users, requiring a credit card and email registration may pose a barrier when starting to use cloud servers. However, some cloud server providers now...
0
by: Faith0G | last post by:
I am starting a new it consulting business and it's been a while since I setup a new website. Is wordpress still the best web based software for hosting a 5 page website? The webpages will be...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.