未初始化的自动变量 [英] Uninitialized auto variables
问题描述
大家好,
我想使用未初始化的自动整数变量导致
未定义的行为?
即
int foo(无效)
{
int bar; / *栏可能是0,或者它可能是非0 * /
返回栏;
}
我有时候当我需要一个int,任何int时这样做。
我想这是一个坏习惯? :-)
问候。
Hello everyone,
I suppose using uninitialized automatic integer variables leads
to undefined behavior?
i.e.
int foo(void)
{
int bar; /* bar may be 0, or it may be non-0 */
return bar;
}
I sometimes do that when I need an int, any int.
I suppose this is a bad habit? :-)
Regards.
推荐答案
Spoon写道:
Spoon wrote:
大家好,
我想使用未初始化的自动整数变量导致
到未定义的行为?
Hello everyone,
I suppose using uninitialized automatic integer variables leads
to undefined behavior?
是。
Yes.
int foo(void)
{
int bar; / *栏可能是0,或者它可能是非0 * /
返回栏;
}
我有时候当我需要一个int,任何int时这样做。
我想这是一个坏习惯? :-)
int foo(void)
{
int bar; /* bar may be 0, or it may be non-0 */
return bar;
}
I sometimes do that when I need an int, any int.
I suppose this is a bad habit? :-)
非常。
(如果任何int将执行,零是一个方便的值。)
-
远见的刺猬
我们没有时间找到我们想知道的一切。
- James Blish,/一个Cy钹的冲突/
Very.
(If "any int" will do, zero is a convenient value.)
--
Far-Fetched Hedgehog
"We did not have time to find out everything we wanted to know."
- James Blish, /A Clash of Cymbals/
Spoon写道:
Spoon wrote:
大家好,
我想使用未初始化的自动整数变量导致
到未定义的行为?
Hello everyone,
I suppose using uninitialized automatic integer variables leads
to undefined behavior?
是。
Yes.
ie
int foo(无效)
{
int bar; / *栏可能是0,或者它可能是非0 * /
返回栏;
}
我有时候当我需要一个int,任何int时这样做。
我想这是一个坏习惯? :-)
i.e.
int foo(void)
{
int bar; /* bar may be 0, or it may be non-0 */
return bar;
}
I sometimes do that when I need an int, any int.
I suppose this is a bad habit? :-)
是的。如果你需要一个随机整数,只需使用rand标准库
函数。
man 3 rand
Yes. If you need a random integer, just use the rand Standard library
function.
man 3 rand
Spoon写道:
Spoon wrote:
Richard Tobin写道:
Richard Tobin wrote:
>文章< 46 *********************** @ news.free.fr>,
Spoon< root @ localhostwrote:
>In article <46***********************@news.free.fr>,
Spoon <root@localhostwrote:
>> ...一个不透明的标识符。任何价值都可以。
>>... an opaque identifier. Any value will do.
什么时候需要不透明的标识符,但不关心它们是否有所不同?为什么不使用45576呢?而不是foo()?
When do you need opaque identifiers but not care about whether they''re
different? Why not just use "45576" instead of "foo()"?
我每次运行只需要一个标识符。
I only needed one identifier per run.
如果只有一个,为什么还需要它?我不需要能够将自己与自己区分开来。
If there''s only one, why do you need it at all? I don''t need to be able
to differentiate myself from myself.
这篇关于未初始化的自动变量的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!