ansi weirdness
Andrew Hume
andrew at alice.UUCP
Mon Sep 10 01:41:23 AEST 1990
In article <11305 at alice.UUCP>, andrew at alice.UUCP (Andrew Hume) writes:
~
~ the following C fragment fails with a strict ANSI compiler (lcc)
~ but compiles with sloppy ones (e.g. gcc):
~
~ typedef int (*fn)(struct x *);
~ extern int fn1(struct x *);
~ extern fn *fp = fn1;
~
~ the ostensible reason is that the two struct x's are different
~ (or at least, have different scopes).
~ this may be technically correct but is just wrong.
~ can anyone explain why anyone would want this batshit behaviour?
let me correct an error and clarify; the fragment contains a bug - it should be
typedef int (*fn)(struct x *);
extern int fn1(struct x *);
extern fn fp = fn1;
i understand technically (i think) what is going on.
the first line introduces a type struct x which goes away
at the end of the prototype and can never be used again.
my question is why didn't ANSI do what C++ does here and export
the type up to file scope?
andrew at research.att.com
More information about the Comp.std.c
mailing list