Velocity Reviews - Computer Hardware Reviews

Velocity Reviews > Newsgroups > Programming > C Programming > Is it ok to define __STDC_VERSION__?

Reply
Thread Tools

Is it ok to define __STDC_VERSION__?

 
 
=?ISO-8859-1?Q?Bj=F8rn_Augestad?=
Guest
Posts: n/a
 
      07-11-2003
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

 
Reply With Quote
 
 
 
 
Eric Sosman
Guest
Posts: n/a
 
      07-11-2003
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__) || ...
^

--
http://www.velocityreviews.com/forums/(E-Mail Removed)
 
Reply With Quote
 
 
 
 
Arthur J. O'Dwyer
Guest
Posts: n/a
 
      07-11-2003

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
 
Reply With Quote
 
=?ISO-8859-1?Q?Bj=F8rn_Augestad?=
Guest
Posts: n/a
 
      07-11-2003
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

 
Reply With Quote
 
Eric Sosman
Guest
Posts: n/a
 
      07-11-2003
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).

----


--
(E-Mail Removed)
 
Reply With Quote
 
Ed Morton
Guest
Posts: n/a
 
      07-11-2003
> 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.

 
Reply With Quote
 
Mark McIntyre
Guest
Posts: n/a
 
      07-11-2003
On Fri, 11 Jul 2003 19:14:57 GMT, in comp.lang.c , Bjørn Augestad
<(E-Mail Removed)> 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 =---
 
Reply With Quote
 
=?ISO-8859-1?Q?Bj=F8rn_Augestad?=
Guest
Posts: n/a
 
      07-12-2003
Mark McIntyre wrote:

> On Fri, 11 Jul 2003 19:14:57 GMT, in comp.lang.c , Bjørn Augestad
> <(E-Mail Removed)> 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

 
Reply With Quote
 
=?ISO-8859-1?Q?Bj=F8rn_Augestad?=
Guest
Posts: n/a
 
      07-12-2003
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

 
Reply With Quote
 
Emmanuel Delahaye
Guest
Posts: n/a
 
      07-12-2003
In 'comp.lang.c', Bjørn Augestad <(E-Mail Removed)> 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- (E-Mail Removed) [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/
 
Reply With Quote
 
 
 
Reply

Thread Tools

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are Off


Similar Threads
Thread Thread Starter Forum Replies Last Post
About typedef -- define the function pointer or define function model? robin liu C Programming 3 04-21-2006 03:26 PM
#define _ and #define __ Brian Takita Ruby 0 01-23-2006 04:34 AM
How to define a define that defines some defines ? theotyflos C Programming 3 02-19-2004 05:07 PM
Mozilla's email program unable to define default font Victor Firefox 15 10-09-2003 09:20 PM
where to define a type? Max VHDL 1 09-12-2003 04:31 PM



Advertisments