Re: do { quit; } else { }

Liste des GroupesRevenir à cl c  
Sujet : Re: do { quit; } else { }
De : david.brown (at) *nospam* hesbynett.no (David Brown)
Groupes : comp.lang.c
Date : 09. Apr 2025, 12:51:55
Autres entêtes
Organisation : A noiseless patient Spider
Message-ID : <vt5n0s$inuo$1@dont-email.me>
References : 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16
User-Agent : Mozilla/5.0 (X11; Linux x86_64; rv:102.0) Gecko/20100101 Thunderbird/102.11.0
On 08/04/2025 20:04, bart wrote:
On 08/04/2025 18:32, Tim Rentsch wrote:
bart <bc@freeuk.com> writes:
>
On 08/04/2025 15:50, David Brown wrote:
>
On 08/04/2025 13:35, bart wrote:
>
But this need not be the case.  For example this is module A:
>
--------------------------
  #include <stdio.h>
>
  typedef struct point {float a; float b;} Point;
>
  float dist(Point);
>
  int main(void) {
  Point p = {3, 4};
  printf("%f\n", dist(p));
  }
--------------------------
>
And this is module B that defines 'dist':
>
>
--------------------------
  #include <math.h>
>
  typedef float length;
  typedef struct _tag {length x, y;} vector;
>
  length dist(vector p) {return sqrt(p.x*p.x + p.y*p.y);}
--------------------------
>
The types involved are somewhat different, but are compatible
enough for it to work.
>
The two types are entirely compatible.
>
Are they?
>
No, they are not.  The type names 'Point' and 'vector' name two
distinct types, and those types are not compatible, because
the two struct tags are different.
>
Because the two types are not compatible, even just calling the
function dist() is undefined behavior.
 I get an incompatible error (from the example you snipped) even when I remove both struct tags.
Of course.  They are different types.

 I can't use the same struct tag in the same scope as one will clash with the other.
Yes.

But if I have the second in an inner scope, then I again get the error.
Yes.

 It doesn't seem to be anything to do with struct tags.
Correct.
Every time you declare a struct - when you have "struct {" or "struct X {", you declare a /new/ type that is incompatible with any other type (except for inter-translation unit compatibility).

 Two typedefs for same struct layout appear to create distinct types; this fails:
"typedef" does not create types - it merely creates an alias for an existing type.  (Is it a questionable choice of keyword?  Yes, it certainly is.  So you have to learn what it means.)  "struct" declarations (and "union" declarations) create types.

    typedef struct {float x, y;} Point;
This creates a new anonymous type, then declares "Point" to be an alias for it.

   typedef struct {float x, y;} vector;
This creates a new anonymous type, then declares "vector" to be an alias for it.
"Point" and "vector" thus refer to different types.

    Point p;
   vector v;
    p=v;
  But this works:
    typedef struct {float x, y;} Point, vector;
This creates a new anonymous type, then declares "Point" and "vector" to be aliases of it.  They therefore refer to the same type.

    Point p;
   vector v;
    p=v;
 So it seems to depend on whether Point and vector share the same internal descriptor for the struct.
 
It depends on whether they are declared as aliases for the same type, or for different types.

In my original example, the structs were defined in separate translation unit, so the compiler has to take things on trust.
 
Yes - as explained in 6.2.7p1 of the standard.  Having them in separate translation units is critical to the difference.

Date Sujet#  Auteur
4 Apr 25 * do { quit; } else { }258Thiago Adams
4 Apr 25 +* Re: do { quit; } else { }2bart
4 Apr 25 i`- Re: do { quit; } else { }1Thiago Adams
4 Apr 25 +* Re: do { quit; } else { }11Kaz Kylheku
4 Apr 25 i+* Re: do { quit; } else { }3Thiago Adams
4 Apr 25 ii`* Re: do { quit; } else { }2Kaz Kylheku
4 Apr 25 ii `- Re: do { quit; } else { }1Chris M. Thomasson
4 Apr 25 i+* Re: do { quit; } else { }4Kaz Kylheku
4 Apr 25 ii+* Re: do { quit; } else { }2Thiago Adams
4 Apr 25 iii`- Re: do { quit; } else { }1Thiago Adams
8 Apr 25 ii`- Re: do { quit; } else { }1candycanearter07
5 Apr 25 i`* Re: do { quit; } else { }3Janis Papanagnou
5 Apr 25 i +- Re: do { quit; } else { }1Janis Papanagnou
6 Apr 25 i `- Re: do { quit; } else { }1Michael S
4 Apr 25 +* Re: do { quit; } else { }242Tim Rentsch
4 Apr 25 i`* Re: do { quit; } else { }241Thiago Adams
6 Apr 25 i `* Re: do { quit; } else { }240Tim Rentsch
6 Apr 25 i  +* Re: do { quit; } else { }222Michael S
6 Apr 25 i  i`* Re: do { quit; } else { }221Tim Rentsch
6 Apr 25 i  i `* Re: do { quit; } else { }220Michael S
7 Apr 25 i  i  `* Re: do { quit; } else { }219Tim Rentsch
7 Apr 25 i  i   `* Re: do { quit; } else { }218Michael S
7 Apr 25 i  i    +* Re: do { quit; } else { }214bart
8 Apr 25 i  i    i`* Re: do { quit; } else { }213David Brown
8 Apr 25 i  i    i `* Re: do { quit; } else { }212bart
8 Apr 25 i  i    i  +* Re: do { quit; } else { }207David Brown
8 Apr 25 i  i    i  i`* Re: do { quit; } else { }206bart
8 Apr 25 i  i    i  i +* Re: do { quit; } else { }58Tim Rentsch
8 Apr 25 i  i    i  i i`* Re: do { quit; } else { }57bart
8 Apr 25 i  i    i  i i +* Re: do { quit; } else { }54Tim Rentsch
8 Apr 25 i  i    i  i i i`* Re: do { quit; } else { }53bart
9 Apr 25 i  i    i  i i i `* Re: do { quit; } else { }52Tim Rentsch
9 Apr 25 i  i    i  i i i  `* Re: do { quit; } else { }51bart
9 Apr 25 i  i    i  i i i   +- Re: do { quit; } else { }1Chris M. Thomasson
9 Apr 25 i  i    i  i i i   +- Re: do { quit; } else { }1Chris M. Thomasson
9 Apr 25 i  i    i  i i i   `* Re: do { quit; } else { }48Tim Rentsch
10 Apr 25 i  i    i  i i i    `* Re: do { quit; } else { }47bart
10 Apr 25 i  i    i  i i i     +* Re: do { quit; } else { }45Kaz Kylheku
10 Apr 25 i  i    i  i i i     i+* Re: do { quit; } else { }2Michael S
10 Apr 25 i  i    i  i i i     ii`- Re: do { quit; } else { }1Kaz Kylheku
10 Apr 25 i  i    i  i i i     i`* Re: do { quit; } else { }42bart
10 Apr 25 i  i    i  i i i     i +* Re: do { quit; } else { }28Keith Thompson
10 Apr 25 i  i    i  i i i     i i`* Re: do { quit; } else { }27bart
10 Apr 25 i  i    i  i i i     i i +* Re: Endless complaints [was Re: do { quit; } else { }]16bart
10 Apr23:18 i  i    i  i i i     i i i+* Re: Endless complaints [was Re: do { quit; } else { }]14Janis Papanagnou
11 Apr00:10 i  i    i  i i i     i i ii`* Re: Endless complaints [was Re: do { quit; } else { }]13bart
11 Apr01:41 i  i    i  i i i     i i ii +- Re: Endless complaints [was Re: do { quit; } else { }]1Keith Thompson
11 Apr03:45 i  i    i  i i i     i i ii +- Re: Endless complaints [was Re: do { quit; } else { }]1Kaz Kylheku
11 Apr09:14 i  i    i  i i i     i i ii `* Re: Endless complaints [was Re: do { quit; } else { }]10David Brown
11 Apr12:32 i  i    i  i i i     i i ii  `* Re: Endless complaints [was Re: do { quit; } else { }]9bart
11 Apr12:50 i  i    i  i i i     i i ii   +* Re: Endless complaints [was Re: do { quit; } else { }]5Michael S
11 Apr12:56 i  i    i  i i i     i i ii   i`* Re: Endless complaints [was Re: do { quit; } else { }]4bart
11 Apr13:12 i  i    i  i i i     i i ii   i `* Re: Endless complaints [was Re: do { quit; } else { }]3Michael S
11 Apr14:12 i  i    i  i i i     i i ii   i  +- Re: Endless complaints [was Re: do { quit; } else { }]1Janis Papanagnou
11 Apr15:55 i  i    i  i i i     i i ii   i  `- Re: Endless complaints [was Re: do { quit; } else { }]1bart
11 Apr14:02 i  i    i  i i i     i i ii   +- Re: Endless complaints [was Re: do { quit; } else { }]1David Brown
11 Apr18:03 i  i    i  i i i     i i ii   +- Re: Endless complaints1Tim Rentsch
11 Apr20:26 i  i    i  i i i     i i ii   `- Re: Endless complaints [was Re: do { quit; } else { }]1Keith Thompson
10 Apr23:27 i  i    i  i i i     i i i`- Re: Endless complaints [was Re: do { quit; } else { }]1Keith Thompson
10 Apr23:23 i  i    i  i i i     i i `* Re: do { quit; } else { }10Keith Thompson
11 Apr00:49 i  i    i  i i i     i i  `* Re: do { quit; } else { }9bart
11 Apr01:59 i  i    i  i i i     i i   `* Re: do { quit; } else { }8Keith Thompson
11 Apr12:26 i  i    i  i i i     i i    `* Re: do { quit; } else { }7Michael S
11 Apr15:11 i  i    i  i i i     i i     +- Re: do { quit; } else { }1David Brown
11 Apr18:22 i  i    i  i i i     i i     +* Re: do { quit; } else { }4Kaz Kylheku
11 Apr20:46 i  i    i  i i i     i i     i+* Re: do { quit; } else { }2bart
11 Apr22:10 i  i    i  i i i     i i     ii`- Re: do { quit; } else { }1Keith Thompson
13 Apr18:45 i  i    i  i i i     i i     i`- Re: do { quit; } else { }1Michael S
11 Apr19:20 i  i    i  i i i     i i     `- Re: do { quit; } else { }1Keith Thompson
10 Apr 25 i  i    i  i i i     i `* Re: do { quit; } else { }13Kaz Kylheku
10 Apr 25 i  i    i  i i i     i  +* Re: do { quit; } else { }10bart
10 Apr 25 i  i    i  i i i     i  i+* Re: do { quit; } else { }2Kaz Kylheku
11 Apr00:02 i  i    i  i i i     i  ii`- Re: do { quit; } else { }1bart
11 Apr02:52 i  i    i  i i i     i  i+* Re: do { quit; } else { }5Tim Rentsch
11 Apr04:51 i  i    i  i i i     i  ii`* Re: do { quit; } else { }4Keith Thompson
11 Apr06:55 i  i    i  i i i     i  ii `* Re: do { quit; } else { }3Tim Rentsch
11 Apr07:00 i  i    i  i i i     i  ii  `* Re: do { quit; } else { }2Keith Thompson
11 Apr12:14 i  i    i  i i i     i  ii   `- Re: do { quit; } else { }1bart
11 Apr05:20 i  i    i  i i i     i  i+- Re: do { quit; } else { }1Keith Thompson
11 Apr05:24 i  i    i  i i i     i  i`- Re: do { quit; } else { }1Keith Thompson
10 Apr 25 i  i    i  i i i     i  +- Re: do { quit; } else { }1bart
10 Apr 25 i  i    i  i i i     i  `- Re: do { quit; } else { }1Kaz Kylheku
11 Apr18:07 i  i    i  i i i     `- Re: do { quit; } else { }1Tim Rentsch
9 Apr 25 i  i    i  i i +- Re: do { quit; } else { }1Richard Damon
9 Apr 25 i  i    i  i i `- Re: do { quit; } else { }1David Brown
9 Apr 25 i  i    i  i `* Re: do { quit; } else { }147David Brown
9 Apr 25 i  i    i  i  +* Re: do { quit; } else { }3Michael S
9 Apr 25 i  i    i  i  i+- Re: do { quit; } else { }1David Brown
11 Apr17:27 i  i    i  i  i`- Re: do { quit; } else { }1James Kuyper
9 Apr 25 i  i    i  i  +* Re: do { quit; } else { }2Michael S
9 Apr 25 i  i    i  i  i`- Re: do { quit; } else { }1David Brown
9 Apr 25 i  i    i  i  +* Re: do { quit; } else { }2Michael S
9 Apr 25 i  i    i  i  i`- Re: do { quit; } else { }1David Brown
9 Apr 25 i  i    i  i  +* Re: do { quit; } else { }7bart
9 Apr 25 i  i    i  i  i`* Re: do { quit; } else { }6David Brown
9 Apr 25 i  i    i  i  i `* Re: do { quit; } else { }5bart
9 Apr 25 i  i    i  i  i  +* Re: do { quit; } else { }2David Brown
9 Apr 25 i  i    i  i  i  i`- Re: do { quit; } else { }1bart
11 Apr01:40 i  i    i  i  i  `* Re: do { quit; } else { }2James Kuyper
11 Apr17:20 i  i    i  i  i   `- Re: do { quit; } else { }1James Kuyper
9 Apr 25 i  i    i  i  `* Re: do { quit; } else { }132Janis Papanagnou
8 Apr 25 i  i    i  +- Re: do { quit; } else { }1Tim Rentsch
9 Apr 25 i  i    i  `* Re: do { quit; } else { }3Ike Naar
8 Apr 25 i  i    `* Re: do { quit; } else { }3Tim Rentsch
6 Apr 25 i  `* Re: do { quit; } else { }17Michael S
6 Apr 25 +- Re: do { quit; } else { }1Lawrence D'Oliveiro
6 Apr 25 `- Re: do { quit; } else { }1David Brown

Haut de la page

Les messages affichés proviennent d'usenet.

NewsPortal