Liste des Groupes | Revenir à cl c |
bart <bc@freeuk.com> writes:I'm showing the code but you keep snipping it! If you want testable code, just wrap it with 'int main() { ... }'. (I assumed you could figure that out.)
On 08/04/2025 18:32, Tim Rentsch wrote:If you want to make a point or ask a question about C code,
>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.
>
I can't use the same struct tag in the same scope as one will clash
with the other. But if I have the second in an inner scope, then I
again get the error.
SHOW THE CODE. And show all of it. Don't make people guess
by showing only some of the code or by giving just a description.
Les messages affichés proviennent d'usenet.