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

Liste des GroupesRevenir à cl c 
Sujet : Re: int a = a (Was: Bart's Language)
De : 643-408-1753 (at) *nospam* kylheku.com (Kaz Kylheku)
Groupes : comp.lang.c
Date : 19. Mar 2025, 18:07:23
Autres entêtes
Organisation : A noiseless patient Spider
Message-ID : <20250319095922.207@kylheku.com>
References : 1 2 3 4 5 6 7
User-Agent : slrn/pre1.0.4-9 (Linux)
On 2025-03-19, David Brown <david.brown@hesbynett.no> wrote:
On 18/03/2025 19:36, Janis Papanagnou wrote:
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".
 
>
It is certainly an idiom, and certainly viewed by gcc as a way to avoid
an "uninitialized" warning (unless "-Winit-self" is also enabled), and
it is an idiom I have seen documented in at least one other compiler
(though I can't remember which - I've read many compiler manuals over
the decades).

I think that this "idiom" is a complete fluke, except in that compiler
where it was documented.

It's easy to see how it can arise "naturally" in a compiler which has
warnings about both uses of uninitialized variables, and about
variables being left uninitialized.

In the "int a = a;" declaration, the initializing expression "a"
is in the scope of a.

Suppose the compiler, when processing the declaration, begins
by extending the compile-time scope object with the name "a",
and seeing that an initializer is present in the syntax, it
flags "a" as being initialized. That suppresses any diagnostics
about a not being initialized.

Then it subsequently processes the initializing expression "a".
At that point "a" is flagged initialized, and so no diagnostic
occurs for the use of uninitialized "a".

That's a bug in the compiler, not an idiom. "a" is positively *not*
initialized until the initializing expression is evaluated.
The compiler must *not* set this "initialized" flag in the
scope information until it has compiled the initializing expression
and moved on to the next declarator, declaration or statement.
That way when it is code-walking the initializing expression,
it will encounter "a" and correctly report that it's being
accessed without having been initialized.

--
TXR Programming Language: http://nongnu.org/txr
Cygnal: Cygwin Native Application Library: http://kylheku.com/cygnal
Mastodon: @Kazinator@mstdn.ca

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