C返回一个++ - 它安全吗? [英] C return a++ - is it safe?
问题描述
如果在C中编码一个包含
的函数,则返回一个++;
是否会增加?这种行为是否可以安全依赖?如果''a''是静态的,或者如
返回ptr->元素++;
>
我在comp.lang.c常见问题中没有找到这个(至少是第一个来自Google的b $ b;似乎有很多)但是没有'''找到它。没有
怀疑有人会告诉我应该在哪里看。
(暂时我正在编码:a ++;返回a - 1; )
-
詹姆斯
If in C one codes a function which includes
return a++;
does ''a'' get incremented? Would the behaviour be safe to rely upon? I
guess this might apply if ''a'' were static or such as
return ptr->element++;
I didn''t find this in the comp.lang.c faq (at least the first one that
came up from Google; there seemed to be many) but didn''t find it. No
doubt someone will tell me where I should have looked.
(For the time being I''m coding: a++; return a - 1; )
--
James
推荐答案
James Harris写道:
James Harris wrote:
>
如果在C中编码一个函数,其中包含
返回一个++;
确实''''增加了吗?
>
If in C one codes a function which includes
return a++;
does ''a'' get incremented?
是。
Yes.
这种行为是否可以安全依赖?
Would the behaviour be safe to rely upon?
是。
Yes.
我想这可能适用于''a''是静态的
I guess this might apply if ''a'' were static
是的。
-
pete
Yes.
--
pete
Richard Harter写道:
Richard Harter wrote:
我相信你错过了他的观点。 Ada有一个非常彻底的
验证套件,并且对Ada编译器可能被称为
的严格限制。 C编译器不是这种情况;任何人
可以产生他们称之为C编译器的东西。甚至可能
没有完全符合C编译器的东西。
他的观点是在现实世界中这是一种事情
你应该检查编译器是否正确。关闭
手,我认为编译器
可能会出现问题,但我可能错了。
I believe you''re missing his point. Ada has a very thorough
validation suite and stringent restrictions on what may be called
an Ada compiler. This isn''t the case with C compilers; anybody
can produce what they call a C compiler. It is even possible
that there is no such thing as a fully conforming C compiler.
His point is that in the real world this is the kind of thing
that you should check whether the compiler gets it right. Off
hand, I would think that it is the sort of thing that a compiler
could be expected to get right but I might well be wrong.
是否存在尝试验证C实现的程序集?
如果是,那么这些程序是否可以免费使用?
- Larry
Do set of programs exist that attempt to validate a C implementation?
If so, are any of these freely available?
- Larry
文章< 13 ************* @ corp.supernews.com> ,Larry__Weiss
< lf*@airmail.netwrites
In article <13*************@corp.supernews.com>, Larry__Weiss
<lf*@airmail.netwrites
> Richard Harter写道:
>Richard Harter wrote:
>我相信你错过了他的观点。 Ada有一个非常彻底的验证套件,对可能被称为Ada编译器的东西有严格的限制。 C编译器不是这种情况;任何人都可以生产他们称之为C编译器的东西。甚至可能没有完全符合C编译器这样的东西。
他的观点是,在现实世界中,这是一种你应该检查编译器的事情。做对了。关闭
手,我认为编译器可能会得到正确的东西,但我可能错了。
>I believe you''re missing his point. Ada has a very thorough
validation suite and stringent restrictions on what may be called
an Ada compiler. This isn''t the case with C compilers; anybody
can produce what they call a C compiler. It is even possible
that there is no such thing as a fully conforming C compiler.
His point is that in the real world this is the kind of thing
that you should check whether the compiler gets it right. Off
hand, I would think that it is the sort of thing that a compiler
could be expected to get right but I might well be wrong.
尝试验证C实现的程序集是什么?
Do set of programs exist that attempt to validate a C implementation?
是
Yes
>如果是这样,这些免费提供吗?
>If so, are any of these freely available?
否
-
\ / \ / \ / \ / \ / \ / \ / \ / \ / \ / \ / \ / \ / \ / \ / \ / \ / \ / \ / \ / \\ \\ / \ / \ / \ / \
\ / \ / \ / \ / \ Chris Hills Staffs England / \ / \ / \ / \\ \\ /
/ \ / \ / ch***@phaedsys.org www.phaedsys.org \ / \ / \
\ / \ / \ / \ / \ / \ / \ / \ / \ / \ / \ / \ / \ / \ / \ / \ / \ / \ / \ / \ / \ / \ / \ / \ / \ / \\ \\ /
No
--
\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\
\/\/\/\/\ Chris Hills Staffs England /\/\/\/\/
/\/\/ ch***@phaedsys.org www.phaedsys.org \/\/\
\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/
这篇关于C返回一个++ - 它安全吗?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!