Re: int a = a (Was: Bart's Language)

Liste des GroupesRevenir à cl c 
Sujet : Re: int a = a (Was: Bart's Language)
De : janis_papanagnou+ng (at) *nospam* hotmail.com (Janis Papanagnou)
Groupes : comp.lang.c
Date : 18. Mar 2025, 19:36:16
Autres entêtes
Organisation : A noiseless patient Spider
Message-ID : <vrcef2$33076$1@dont-email.me>
References : 1 2 3 4 5
User-Agent : Mozilla/5.0 (X11; Linux x86_64; rv:45.0) Gecko/20100101 Thunderbird/45.8.0
On 18.03.2025 19:04, Kenny McCormack wrote:
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".

Wow! - It would never have occurred to me that "int a = a;" being
considered an idiom, let alone a "common idiom".

I certainly never saw it in any C code nor have seen it mentioned
as idiomatic code [to prevent compiler warning messages]. - This is
IMO just sick; in all respects. Compilers not warning about it (you
may have just missed to complete the RHS expression), programmers
working around a compiler deficiency by code that just rises more
questions (than solving any issue).

So it makes perfect sense for the compiler not to warn about it!

(Obviously mileages on that vary.)

 
Wouldn't it just be easier and clearer to write: int a = 0;
and be done with it?

Indeed! - More generally, there's a [general, non-language specific]
coding _idiom_ to ("always", sort of) initialize your variables, and
this is certainly part of many coding guidelines and recommendations
I've seen.

 
"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)

Yes. (Unless it's really an "idiom"; then we can justify every idea
we like by that classification.)

Janis


Date Sujet#  Auteur
18 Mar 25 * Bart's Language57bart
18 Mar 25 `* Re: Bart's Language56Waldek Hebisch
18 Mar 25  `* Re: Bart's Language55bart
18 Mar 25   `* Re: Bart's Language54Waldek Hebisch
18 Mar 25    +* Re: Bart's Language46bart
18 Mar 25    i+* Re: Bart's Language36David Brown
18 Mar 25    ii`* int a = a (Was: Bart's Language)35Kenny McCormack
18 Mar 25    ii +* Re: int a = a (Was: Bart's Language)25Janis Papanagnou
18 Mar 25    ii i+- Re: int a = a (Was: Bart's Language)1Kaz Kylheku
19 Mar 25    ii i`* Re: int a = a (Was: Bart's Language)23David Brown
19 Mar 25    ii i +- Re: int a = a (Was: Bart's Language)1Kaz Kylheku
19 Mar 25    ii i +* Re: int a = a14Keith Thompson
20 Mar 25    ii i i+* Re: int a = a12Tim Rentsch
20 Mar 25    ii i ii`* Re: int a = a11Keith Thompson
20 Mar 25    ii i ii +* Re: int a = a8David Brown
20 Mar 25    ii i ii i`* Re: int a = a7Keith Thompson
21 Mar 25    ii i ii i `* Re: int a = a6David Brown
21 Mar 25    ii i ii i  `* Re: int a = a5Keith Thompson
21 Mar 25    ii i ii i   +- Re: int a = a1David Brown
22 Mar 25    ii i ii i   `* Re: int a = a3Tim Rentsch
22 Mar 25    ii i ii i    `* Re: int a = a2Keith Thompson
28 Apr 25    ii i ii i     `- Re: int a = a1Tim Rentsch
29 Apr 25    ii i ii `* Re: int a = a2Tim Rentsch
29 Apr 25    ii i ii  `- Re: int a = a1Keith Thompson
20 Mar 25    ii i i`- Re: int a = a1David Brown
19 Mar 25    ii i +* Re: int a = a (Was: Bart's Language)5Chris M. Thomasson
20 Mar 25    ii i i`* Re: int a = a (Was: Bart's Language)4David Brown
20 Mar 25    ii i i `* Re: int a = a (Was: Bart's Language)3bart
20 Mar 25    ii i i  `* Re: int a = a (Was: Bart's Language)2David Brown
20 Mar 25    ii i i   `- Re: int a = a (Was: Bart's Language)1wij
20 Mar 25    ii i `* Re: int a = a (Was: Bart's Language)2Tim Rentsch
20 Mar 25    ii i  `- Re: int a = a (Was: Bart's Language)1David Brown
18 Mar 25    ii +* Re: int a = a (Was: Bart's Language)3David Brown
18 Mar 25    ii i`* Re: int a = a (Was: Bart's Language)2Janis Papanagnou
19 Mar 25    ii i `- Re: int a = a (Was: Bart's Language)1David Brown
19 Mar 25    ii `* Re: int a = a (Was: Bart's Language)6Tim Rentsch
19 Mar 25    ii  +* Re: int a = a2Keith Thompson
27 Apr 25    ii  i`- Re: int a = a1Tim Rentsch
19 Mar 25    ii  +- Re: int a = a (Was: Bart's Language)1David Brown
19 Mar 25    ii  `* Re: int a = a (Was: Bart's Language)2Rosario19
20 Mar 25    ii   `- Re: int a = a (Was: Bart's Language)1Tim Rentsch
20 Mar 25    i`* Re: Bart's Language9Waldek Hebisch
21 Mar 25    i `* Re: Bart's Language8Keith Thompson
22 Mar 25    i  +* Re: Bart's Language5Waldek Hebisch
22 Mar 25    i  i`* Re: Bart's Language4James Kuyper
22 Mar 25    i  i +* Re: Bart's Language2Waldek Hebisch
23 Mar 25    i  i i`- Re: Bart's Language1James Kuyper
23 Mar 25    i  i `- By definition... (Was: Bart's Language)1Kenny McCormack
27 Apr 25    i  `* Re: Bart's Language2Tim Rentsch
27 Apr 25    i   `- Re: Bart's Language1Keith Thompson
18 Mar 25    `* Re: Bart's Language7bart
20 Mar 25     `* Re: Bart's Language6Waldek Hebisch
21 Mar 25      +* Re: Bart's Language4Kaz Kylheku
21 Mar 25      i`* Re: Bart's Language3bart
21 Mar 25      i `* Re: Bart's Language2Kaz Kylheku
22 Mar 25      i  `- Re: Bart's Language1Tim Rentsch
21 Mar 25      `- Re: Bart's Language1bart

Haut de la page

Les messages affichés proviennent d'usenet.

NewsPortal