Sujet : int a = a (Was: Bart's Language)
De : gazelle (at) *nospam* shell.xmission.com (Kenny McCormack)
Groupes : comp.lang.cDate : 18. Mar 2025, 19:04:27
Autres entêtes
Organisation : The official candy of the new Millennium
Message-ID : <vrccjb$b3m6$1@news.xmission.com>
References : 1 2 3 4
User-Agent : trn 4.0-test77 (Sep 1, 2010)
In article <
vrc75b$2r4lt$1@dont-email.me>,
David Brown <
david.brown@hesbynett.no> wrote:
...
gcc won't warn until you say '-Wextra', and then only for:
>
int a = a + 1;
>
People would not normally write "int a = a;". It is used as a common
idiom meaning "I know it is not clear to the compiler that the variable
is always initialised before use, but /I/ know it is - so disable the
use-without-initialisation warnings for this variable". So it makes
perfect sense for the compiler not to warn about it!
Wouldn't it just be easier and clearer to write: int a = 0;
and be done with it?
"int a = a + 1;", on the other hand, clearly attempts to read the value
of "a" before it is initialised, and a warning is issued if
"-Wuninitialized" is enabled. This warning is part of "-Wall".
How is: int a = a + 1;
conceptually different from: int a = a;
Both are expressions involving 'a'.
Isn't 'a' being used un-initialised in both cases?
(You have to know the value of 'a' in order to evaluate the expression: a)
-- "If our country is going broke, let it be from feeding the poor and caring forthe elderly. And not from pampering the rich and fighting wars for them." --Living Blue in a Red State--