Re: Naming conventions (was Re: valgrind leak I can't find)

Liste des GroupesRevenir à l c 
Sujet : Re: Naming conventions (was Re: valgrind leak I can't find)
De : jameskuyper (at) *nospam* alumni.caltech.edu (James Kuyper)
Groupes : comp.lang.c
Date : 26. Aug 2024, 05:47:45
Autres entêtes
Organisation : A noiseless patient Spider
Message-ID : <vagtt1$2ahdn$3@dont-email.me>
References : 1 2 3 4 5 6 7 8
User-Agent : Mozilla Thunderbird
On 8/25/24 12:55, Janis Papanagnou wrote:
On 23.08.2024 17:57, James Kuyper wrote:
[...]
>
That's possible because C defines separate name spaces of identifiers
(not to be confused with C++ namespaces) for labels, tags, each struct
or union type, and attributes; all other identifiers are in the ordinary
name space. Because of the relevant grammar rules, names in the
different spaces can never occur in locations where it is ambiguous as
to which name space the identifier is from. Therefore, C allows you do
use the same identifier in different name spaces in the same scope with
different meanings. For example, identifiers in the tag name space are
always prefixed with struct, union or enum, so they can never be
confused with names from the ordinary name space.
>
In C++, there are separate name spaces only for macros and labels. All
other identifiers are in the same name space, including tags. Class,
struct, and union members are not controlled by name spaces, but by
scope rules that are different from those in C. That's what allows you
to use a tag without a preceding "class", "struct", or "union" keyword.
Note: The name space for macros isn't really comparable to the other
name spaces I've mentioned, which is why C doesn't have such a name
space. Macros are replaced with their expansions during translation
phase 3, whereas the other name spaces only become meaningful during
translation phase 8.
>
If C were changed to allow use of tags without "struct" or "union"
before them, the tag name space would have to be merged into the
ordinary name space, and that would break all kinds of legacy code that
uses the same identifier as a tag and as an identifier in the ordinary
name space. That would be a backwards incompatible change, and the
committee tends to avoid such changes.
>
I recall (when I learned C) that the type definitions confused me.
>
The clear things were ('typedef'-)definitions like
>
typedef struct { double re, im; } complex;
>
But then there were also examples like
>
typedef struct tnode {
...
struct tnode * right;
} TREENODE, *TREEPTR;
>
(Both examples taken from an old K&R book.)
>
In the first case there's no struct name (only the typedef'd one.

"A declaration other than a static_assert or attribute declaration shall
declare at least a declarator (other than the parameters of a function
or the members of a structure or union), a tag, or the members of an
enumeration." (6.7p2)

Since the typedef declares a declarator (the typedef name) it don't need
to declare a tag.

In the second case an explicit struct name (necessary for the
type self-reference inside the struct) despite type names being
defined. - Appeared crude to me (and still does).


I don't recall internal name-spaces (as you explain them above)
having been documented and explained. But I may be misremembering.

"The C Programming Language", 1st edition makes no mention of name
spaces as such. However, the 2nd Edition was updated to match the latest
draft version of the C89 standard, and explains name spaces in section
A.11.1, which is titled "Lexical Scope". The final C89 standard
described scope in section 3.1.2.1, and name spaces in 3.1.2.3.


Date Sujet#  Auteur
22 Aug 24 * valgrind leak I can't find26Mark Summerfield
22 Aug 24 +- Re: valgrind leak I can't find1Ben Bacarisse
22 Aug 24 +* Re: valgrind leak I can't find11Bart
22 Aug 24 i`* Re: valgrind leak I can't find10Thiago Adams
22 Aug 24 i `* Re: valgrind leak I can't find9Annada Behera
22 Aug 24 i  +* Naming conventions (was Re: valgrind leak I can't find)6Janis Papanagnou
22 Aug 24 i  i`* Re: Naming conventions (was Re: valgrind leak I can't find)5Thiago Adams
23 Aug 24 i  i +- Re: Naming conventions (was Re: valgrind leak I can't find)1Janis Papanagnou
23 Aug 24 i  i `* Re: Naming conventions (was Re: valgrind leak I can't find)3James Kuyper
25 Aug 24 i  i  `* Re: Naming conventions (was Re: valgrind leak I can't find)2Janis Papanagnou
26 Aug 24 i  i   `- Re: Naming conventions (was Re: valgrind leak I can't find)1James Kuyper
24 Aug 24 i  `* Re: valgrind leak I can't find2Blue-Maned_Hawk
24 Aug 24 i   `- Re: valgrind leak I can't find1Keith Thompson
22 Aug 24 +- Re: valgrind leak I can't find1Stefan Ram
22 Aug 24 +- Re: valgrind leak I can't find1Ike Naar
22 Aug 24 +- Re: valgrind leak I can't find1Stefan Ram
22 Aug 24 +- Re: valgrind leak I can't find1Kaz Kylheku
22 Aug 24 `* Re: valgrind leak I can't find9Mark Summerfield
22 Aug 24  +- Re: valgrind leak I can't find1Kaz Kylheku
23 Aug 24  +* Re: valgrind leak I can't find6Stefan Ram
23 Aug 24  i`* Re: valgrind leak I can't find5Bart
23 Aug 24  i `* Re: valgrind leak I can't find4Michael S
23 Aug 24  i  +* Re: valgrind leak I can't find2James Kuyper
23 Aug 24  i  i`- Re: valgrind leak I can't find1James Kuyper
23 Aug 24  i  `- Re: valgrind leak I can't find1David Brown
23 Aug 24  `- Re: valgrind leak I can't find1James Kuyper

Haut de la page

Les messages affichés proviennent d'usenet.

NewsPortal