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, 13:36:15
Autres entêtes
Organisation : A noiseless patient Spider
Message-ID : <vt5pjv$inuo$5@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 09/04/2025 12:51, bart wrote:
On 09/04/2025 10:42, David Brown wrote:
On 08/04/2025 18:28, bart wrote:
On 08/04/2025 15:50, David Brown wrote:
 
The two types are entirely compatible.
>
>
Are they?
>
Yes.
>
So why does gcc report an error here (the two types are from my example):
>
   typedef struct point {float a; float b;} Point;
>
   typedef float length;
   typedef struct _tag {length x, y;} vector;
>
   Point p;
   vector v;
>
   p=v;
>
c.c:14:5: error: incompatible types when assigning to type 'Point' {aka 'struct point'} from type
ector' {aka 'struct _tag'}
    14 |   p=v;
       |     ^
>
>
That is a different situation.  In the first case, the types were defined in different translation units - and are compatible.  In the second case, they are within the same translation unit, and are not compatible.
 This doesn't make sense at all.
 Turning it around, you're saying that if T an U are incompatible types within the same translation unit, they suddenly become compatible if split across two translation units?
 
In the specific case of structs and unions matching the requirements in 6.2.7, yes.  /Please/ read that section of the standard before making any more posts about it.
There are plenty of differences between compiling two C files independently, and pasting them directly together in one file and compiling that.  This is one of those differences.

 
In C, if you declare two structs in the same translation unit with the same field types and the same field names, they are still different types.  That is important for making new types - it is how you get strong typing in C (albeit with less user convenience than in some other languages).  It means that you can't mix up two types just because of coincidences in the fields.
>
This means that when you have a struct declaration in two translation units (locally in the C file, or via a header file - there is no distinction), they form two different types as they are separate declarations.  If C did not specify that these were compatible, it would be impossible (without UB) to use struct or union types across translation units.
 So, yes, you are saying that. In short, if a programmer says that incompatible types T and U are the same (where the compiler can only see T in module A and U in module B), then the programmer must be trusted, even though they would be wrong.
 
Yes.

Note that I, as the programmer, said this:
 "The types involved are somewhat different, but are compatible enough for it to work."
 
It's not quite like that - C says that although they are different types (since they are in different translation units), they are compatible in this situation.  Not "compatible enough to work", but /actually/ compatible in the specific C technical sense.  (Section 6.2.7 has "compatible type" in italics - it defines what is meant by that term in the C language.)

What you are saying is that even though I was actually telling the truth, I was wrong. But I would be right if I lied about it....
 
No, you were not telling the truth - you were wildly mixing things.

We're either through the Looking-Glass at this point, or somewhere not in Kansas!
 I'll have to think about this before replying to any other points.
Marvellous - I'd appreciate you putting more thought into this, and less knee-jerk reactions and exaggerations.  Please also read the relevant parts of the standards before replying - at the very least, section 6.2.7p1 and section 6.2.2.  Once you have read these and tried to understand them, it will be a lot easier to clear up any remaining issues.

 
You are still wrong.
 Never mind. I've just spotted this at the end. In that case, and given what you said above where you arguing that Black is White, discussion is futile.
 
I believe there is still hope.  But it does require you to read and think.

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