可以定义__STDC_VERSION__吗? [英] Is it ok to define __STDC_VERSION__?

查看:482
本文介绍了可以定义__STDC_VERSION__吗?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述




我目前使用的编译器会在以下语句中发出警告:

#if defined(__ STDC_VERSION__)|| __STDC_VERSION__< 19990601L

....

#endif


编译器抱怨__STDC_VERSION__没有定义。很明显

并没有使表达式短路,而是评估

||的两边。作为解决方法,我将语句改为:


#if!defined(__ STDC_VERSION__)

#define __STDC_VERSION__ 0

#endif


#if __STDC_VERSION__< 19990601L

....

#endif


除了任何拼写错误,在用户代码中定义__STDC_VERSION__是否合法?


-

boa


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

解决方案

< blockquote> Bj?Augestad写道:




我目前使用的编译器会在以下语句中发出警告:
#if已定义(__ STDC_VERSION__)|| __STDC_VERSION__< 19990601L
...
#endif

编译器抱怨__STDC_VERSION__没有定义。它显然不会使表达式短路,而是评估
||的两个方面。 [...]




如果没有定义__STDC_VERSION__那么应该如此。

你确定你在

测试表达式的开头没有错过`!''吗?


#if!defined(__ STDC_VERSION__)|| ...

^


-
Er ********* @ sun.com




2003年7月11日星期五,[ISO-8859-1] Bj?Augestad写道:


我目前使用的编译器会在以下语句中发出警告:
#if defined(__ STDC_VERSION__) || __STDC_VERSION__< 19990601L
...
#endif

编译器抱怨__STDC_VERSION__没有定义。它显然不会使表达式短路,而是评估
||的两个方面。作为一种解决方法,我将语句改为:
#if!defined(__ STDC_VERSION__)
#define __STDC_VERSION__ 0
#endif

#if __STDC_VERSION__< 19990601L
...
#endif

除了任何拼写错误,在用户代码中定义__STDC_VERSION__是否合法?




Hallvard亲切地追踪了使这个

无效的标准。但是,一个等价但合法的解决方法是


#ifndef __STDC_VERSION__

#define C_VERSION_NUMBER 0

#else

#define C_VERSION_NUMBER __STDC_VERSION__

#endif


#if C_VERSION_NUMBER< 19990601L

....

#endif


或其他任何行。


请注意,您的编译器可能会抱怨__STDC_VERSION __'不是

被定义,但如果它实际上拒绝编译您的程序,因为

这个,它'这不符合标准的不止一种方式。

我自己也赞同尽可能摆脱最无害的b $ b无害警告的想法。 />

-Arthur


Eric Sosman写道:

Bj?rn Augestad写道:



我目前使用的编译器会在以下语句中发出警告:
#if defined(__ STDC_VERSION__)|| __STDC_VERSION__< 19990601L
...
#endif

编译器抱怨__STDC_VERSION__没有定义。它显然不会使表达式短路,而是评估
||的两个方面。 [...]



如果没有定义__STDC_VERSION__那么应该如此。你确定在测试表达式的开头你没有错过`!''吗?

#if!defined(__ STDC_VERSION__)|| ...
^




我向所有已经回复原帖的人道歉,其中有一个

非常草率和不正确问题的插图。对于一些愚蠢的原因我决定编写代码而不是从源代码复制它

文件,我甚至混合了来自_POSIX_C_SOURCE的元素。 Duh。


这是造成问题的确切代码。它来自libclc文件

clc_settings.h并导致os20嵌入式操作系统的st20cc交叉编译器v.1.9.6

(windows版本)出现问题:


/ *处理C89和C99之间的差异* /

#if!defined __STDC_VERSION__ || __STDC_VERSION__< 199901L

#define CLC_RESTRICT

#else

#define CLC_RESTRICT restrict

#endif

再次感谢所有人。我将在星期一试用更多的编译器

并尝试提供一个便携且可行的解决方案。


-

boa


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


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

解决方案

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



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


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


这篇关于可以定义__STDC_VERSION__吗?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆