Sujet : Re: int a = a (Was: Bart's Language)
De : tr.17687 (at) *nospam* z991.linuxsc.com (Tim Rentsch)
Groupes : comp.lang.cDate : 20. Mar 2025, 09:32:54
Autres entêtes
Organisation : A noiseless patient Spider
Message-ID : <868qp0p0eh.fsf@linuxsc.com>
References : 1 2 3 4 5 6 7
User-Agent : Gnus/5.11 (Gnus v5.11) Emacs/22.4 (gnu/linux)
Rosario19 <
Ros@invalid.invalid> writes:
On Tue, 18 Mar 2025 23:52:20 -0700, Tim Rentsch wrote:
>
(Kenny McCormack) writes:
>
David Brown 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!
>
An addle-brained view. Anyone who thinks that should be forcibly
removed from any activity involving software development.
>
Wouldn't it just be easier and clearer to write: int a = 0;
and be done with it?
>
There are two problems: one, the semantics are different; and
two, the impression given of the author's intent is different.
It's kind of like saying "isn't it just easier and clearer to
write 'red' rather than 'yellow'?" Writing 'int a = 0;' might be
better or it might be worse, depending on one's point of view,
but it shouldn't be considered either more clear or less clear,
because it isn't saying the same thing.
>
int a=a;
for me initialize "a" variable with a value the compiler found
right as in
>
int a;
>
only possibly silence compiler warning for variable not
initializated
If you want to take it that way, there is nothing wrong with
that.
But it's a mistake to assume everyone else will also take it to
mean the same thing that you do.