473,396 Members | 1,749 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,396 software developers and data experts.

Is it ok to define __STDC_VERSION__?

Hi,

I currently use a compiler which emits a warning on the following statement:
#if defined(__STDC_VERSION__) || __STDC_VERSION__ < 19990601L
....
#endif

The compiler complains that __STDC_VERSION__ isn't defined. It obviously
doesn't short circuit the expression, but evaluates both sides of the
||. I have, as a workaround, changed the statements into this:

#if !defined(__STDC_VERSION__)
#define __STDC_VERSION__ 0
#endif

#if __STDC_VERSION__ < 19990601L
....
#endif

Apart from any typos, is it legal to define __STDC_VERSION__ in user code?

--
boa

libclc home: http://libclc.sourceforge.net

Nov 13 '05 #1
11 7649
Bjørn Augestad wrote:

Hi,

I currently use a compiler which emits a warning on the following statement:
#if defined(__STDC_VERSION__) || __STDC_VERSION__ < 19990601L
...
#endif

The compiler complains that __STDC_VERSION__ isn't defined. It obviously
doesn't short circuit the expression, but evaluates both sides of the
||. [...]


As it should, if __STDC_VERSION__ isn't defined. Are
you sure you're not missing a `!' at the beginning of the
test expression?

#if !defined(__STDC_VERSION__) || ...
^

--
Er*********@sun.com
Nov 13 '05 #2

On Fri, 11 Jul 2003, [ISO-8859-1] Bjørn Augestad wrote:

I currently use a compiler which emits a warning on the following statement:
#if defined(__STDC_VERSION__) || __STDC_VERSION__ < 19990601L
...
#endif

The compiler complains that __STDC_VERSION__ isn't defined. It obviously
doesn't short circuit the expression, but evaluates both sides of the
||. I have, as a workaround, changed the statements into this:

#if !defined(__STDC_VERSION__)
#define __STDC_VERSION__ 0
#endif

#if __STDC_VERSION__ < 19990601L
...
#endif

Apart from any typos, is it legal to define __STDC_VERSION__ in user code?


Hallvard has kindly tracked down the bit of the standard that makes this
invalid. However, an equivalent but legal workaround would be

#ifndef __STDC_VERSION__
#define C_VERSION_NUMBER 0
#else
#define C_VERSION_NUMBER __STDC_VERSION__
#endif

#if C_VERSION_NUMBER < 19990601L
....
#endif

or anything along those lines.

Note that your compiler may be complaining about __STDC_VERSION__'s not
being defined, but if it actually refuses to compile your program because
of this, it's not conforming to the Standard in more than one way.
I myself also subscribe to the idea of getting rid of even the most
harmless warnings, though.

-Arthur
Nov 13 '05 #3
Eric Sosman wrote:
Bjørn Augestad wrote:
Hi,

I currently use a compiler which emits a warning on the following statement:
#if defined(__STDC_VERSION__) || __STDC_VERSION__ < 19990601L
...
#endif

The compiler complains that __STDC_VERSION__ isn't defined. It obviously
doesn't short circuit the expression, but evaluates both sides of the
||. [...]

As it should, if __STDC_VERSION__ isn't defined. Are
you sure you're not missing a `!' at the beginning of the
test expression?

#if !defined(__STDC_VERSION__) || ...
^


My apologies to all that has answered the original post, which had a
very sloppy and incorrect illustration of the problem. For some stupid
reason I decided to write the code instead of copying it from the source
file, and I even mixed in elements from _POSIX_C_SOURCE. Duh.

Here is the exact code causing problems. It's from the libclc file
clc_settings.h and causes problems on the st20cc cross compiler v. 1.9.6
(windows version) for the os20 embedded os:

/* Handle differences between C89 and C99 */
#if !defined __STDC_VERSION__ || __STDC_VERSION__ < 199901L
# define CLC_RESTRICT
#else
# define CLC_RESTRICT restrict
#endif
Thanks again to all. I'll experiment more with the compiler on monday
and try to come up with a portable and working solution.

--
boa

libclc home: http://libclc.sourceforge.net

Nov 13 '05 #4
> Hi,

I currently use a compiler which emits a warning on the following statement:
#if defined(__STDC_VERSION__) || __STDC_VERSION__ < 19990601L

^^
Shouldn't that be an "&&"?

Ed.

Nov 13 '05 #5
Bjørn Augestad wrote:

Here is the exact code causing problems. It's from the libclc file
clc_settings.h and causes problems on the st20cc cross compiler v. 1.9.6
(windows version) for the os20 embedded os:

/* Handle differences between C89 and C99 */
#if !defined __STDC_VERSION__ || __STDC_VERSION__ < 199901L
# define CLC_RESTRICT
#else
# define CLC_RESTRICT restrict
#endif

Thanks again to all. I'll experiment more with the compiler on monday
and try to come up with a portable and working solution.


Actually, the `defined' piece is unnecessary:

#if __STDC_VERSION__ < 199901L

is a portable solution, because any unrecognized identifiers
in an #if or #elif directive are replaced with zeroes.

Another formulation found favor with pre-Standard compilers,
some of whose preprocessors simply deleted unrecognized names
in such expressions:

#if __STDC_VERSION__ + 0 < 199901L

the idea being that you'd wind up with `value + 0' or with
`0 + 0' (the Standard answers) or with unadorned `+ 0' (for
some pre-Standard compilers). You might want to see if this
old dodge might calm your compiler's nervousness.

Finally, there's Arthur O'Dwyer's suggestion, using the
defined-ness of __STDC_VERSION__ to govern the definition of
an "intermediate" symbol, and then testing that symbol. For
the case at hand, you could eliminate the intermediate with
some extra coding:

#ifdef __STDC_VERSION__
#if __STDC_VERSION__ >= 199901L
#define CLC_RESTRICT restrict
#endif
#endif
#ifndef CLC_RESTRICT
#define CLC_RESTRICT /* nil */
#endif

This, I think, stands the best chance of quieting the
whines -- but nothing's guaranteed; the compiler is within
its rights to complain about the vapidity of American beer,
if it so chooses. It must, though, accept and translate
your code (barring other problems, of course).

----
--
Er*********@sun.com
Nov 13 '05 #6
On Fri, 11 Jul 2003 19:14:57 GMT, in comp.lang.c , Bjørn Augestad
<bo*@metasystems.no.spam.to.me> wrote:
Hi,

I currently use a compiler which emits a warning on the following statement:
#if defined(__STDC_VERSION__) || __STDC_VERSION__ < 19990601L
...
#endif

The compiler complains that __STDC_VERSION__ isn't defined.


Is it a pre-ANSI compiler, and you're trying to use a header that
doesn't belong to it? Did you a header from some another
implementation?
--
Mark McIntyre
CLC FAQ <http://www.eskimo.com/~scs/C-faq/top.html>
CLC readme: <http://www.angelfire.com/ms3/bchambless0/welcome_to_clc.html>
----== Posted via Newsfeed.Com - Unlimited-Uncensored-Secure Usenet News==----
http://www.newsfeed.com The #1 Newsgroup Service in the World! >100,000 Newsgroups
---= 19 East/West-Coast Specialized Servers - Total Privacy via Encryption =---
Nov 13 '05 #7
Mark McIntyre wrote:
On Fri, 11 Jul 2003 19:14:57 GMT, in comp.lang.c , Bjørn Augestad
<bo*@metasystems.no.spam.to.me> wrote:

Hi,

I currently use a compiler which emits a warning on the following statement:
#if defined(__STDC_VERSION__) || __STDC_VERSION__ < 19990601L
...
#endif

The compiler complains that __STDC_VERSION__ isn't defined.

Is it a pre-ANSI compiler,


Pre C99, but post C89 AFAIK. ;-)
The st20cc compiler is quite nice to work with, apart for a few quirks.

and you're trying to use a header that doesn't belong to it? Did you a header from some another
implementation?


Pretty sure I don't, I'll check it though. I just get a warning about
__STDC_VERSION__ beeing undefined when I compile the libclc source code,
a warning I'd like to get rid of. The rest of libclc worked perfectly
from day one, BTW. :-)
--
boa

libclc home: http://libclc.sourceforge.net

Nov 13 '05 #8
Eric Sosman wrote:

[snip]


Actually, the `defined' piece is unnecessary:

#if __STDC_VERSION__ < 199901L

is a portable solution, because any unrecognized identifiers
in an #if or #elif directive are replaced with zeroes.
That's what I thought too, but according to the official libclc archives
(aka google, http://tinyurl.com/gpss), the "#if !defined" construct has
been there since day one, code written by Dan Pop. I assume he had a
reason to do it like that, instead of just writing
#if __STDC_VERSION__ < 199901L ?
[...]
Finally, there's Arthur O'Dwyer's suggestion, using the
defined-ness of __STDC_VERSION__ to govern the definition of
an "intermediate" symbol, and then testing that symbol. For
the case at hand, you could eliminate the intermediate with
some extra coding:

#ifdef __STDC_VERSION__
#if __STDC_VERSION__ >= 199901L
#define CLC_RESTRICT restrict
#endif
#endif
#ifndef CLC_RESTRICT
#define CLC_RESTRICT /* nil */
#endif

This, I think, stands the best chance of quieting the
whines -- but nothing's guaranteed; the compiler is within
its rights to complain about the vapidity of American beer,
if it so chooses. It must, though, accept and translate
your code (barring other problems, of course).


Looks fool proof to me and is most likely the way to go. :-)
--
boa

libclc home: http://libclc.sourceforge.net

Nov 13 '05 #9
In 'comp.lang.c', Bjørn Augestad <bo*@metasystems.no.spam.to.me> wrote:
I currently use a compiler which emits a warning on the following
statement: #if defined(__STDC_VERSION__) || __STDC_VERSION__ < 19990601L
Try with &&.
...
#endif

--
-ed- em**********@noos.fr [remove YOURBRA before answering me]
The C-language FAQ: http://www.eskimo.com/~scs/C-faq/top.html
<blank line>
FAQ de f.c.l.c : http://www.isty-info.uvsq.fr/~rumeau/fclc/
Nov 13 '05 #10
In <3F***************@sun.com> Eric Sosman <Er*********@sun.com> writes:
Bj=F8rn Augestad wrote:
=

Here is the exact code causing problems. It's from the libclc file
clc_settings.h and causes problems on the st20cc cross compiler v. 1.9.=

6
(windows version) for the os20 embedded os:
=

/* Handle differences between C89 and C99 */
#if !defined __STDC_VERSION__ || __STDC_VERSION__ < 199901L
# define CLC_RESTRICT
#else
# define CLC_RESTRICT restrict
#endif
=

Thanks again to all. I'll experiment more with the compiler on monday
and try to come up with a portable and working solution.


Actually, the `defined' piece is unnecessary:

#if __STDC_VERSION__ < 199901L

is a portable solution, because any unrecognized identifiers
in an #if or #elif directive are replaced with zeroes.


Nope, it ain't, because __STDC_VERSION__ may be any kind of preprocessor
magic which isn't a macro. So, before attempting to use it as a macro,
you *have* to check that a macro with this name is defined.

Your argument would have worked for STDC_VERSION, but thingies starting
with __ are special.

Dan
--
Dan Pop
DESY Zeuthen, RZ group
Email: Da*****@ifh.de
Nov 13 '05 #11
Dan Pop wrote:
[snip]

You can try rewriting the code like this, but there is no guarantee that
the broken preprocessor won't barf again:

#if !defined __STDC_VERSION__
# define CLC_RESTRICT
#elif __STDC_VERSION__ < 199901L
# define CLC_RESTRICT
#else
# define CLC_RESTRICT restrict
#endif

If it works, throw in a comment explaining the goofy code.


It didn't work. Now the compiler whines about the #elif using an
undefined macro. I guess I can live with that one warning, as the rest
of libclc works like a charm. :-)

Thanks.

--
boa

libclc home: http://libclc.sourceforge.net

Nov 13 '05 #12

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

Similar topics

20
by: srinivas reddy | last post by:
I have defined some variables using #define preprocessor instruction. And then later I checked whether I had defined a variable. Sometimes even though a variable have been defined, #if...
9
by: Tim Clacy | last post by:
Would some kind soul suggest a pre-processor test for the C++ language revision whereby class static variables were specified to refer to the same instance? Specifically, the following Singleton...
5
by: Tom St Denis | last post by:
I'm adding UTF-8 support to my crypto lib and I want to avoid dying on pre-C99 platforms. I plan to just typedef wchar_t to unsigned long for them. Is there a #define for C99 compliance I could...
71
by: David T. Ashley | last post by:
Where is the best place to define TRUE and FALSE? Are they in any of the standard include files, ever? Do any standards apply? What I've traditionally done is something like: #ifndef...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
by: ryjfgjl | last post by:
In our work, we often receive Excel tables with data in the same format. If we want to analyze these data, it can be difficult to analyze them because the data is spread across multiple Excel files...
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
0
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
0
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
0
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...
0
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows...
0
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each...

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.