draves@harvard.ARPA (Richard Draves) (11/12/84)
Don't the normal scope rules hold for typedef?
The following program produced errors under 4.2BSD:
typedef int foo;
main()
{
auto int foo;
foo = 2;
}
"test.c", line 5: illegal type combination
"test.c", line 7: syntax error
"test.c", line 7: warning: illegal combination of pointer and integer, op =
"test.c", line 7: unknown size
"test.c", line 7: cannot recover from earlier errors: goodbye!
Stylistic considerations aside, why isn't foo a variable inside main,
and a type outside? And why can't cc recover from such simple errors?
Rich
gwyn@brl-tgr.ARPA (Doug Gwyn <gwyn>) (11/12/84)
> typedef int foo; > > main() > { > auto int foo; > > foo = 2; > } > > Stylistic considerations aside, why isn't foo a variable inside main, > and a type outside? Typedefs are not scoped. They define synonyms for (possibly complicated) data types. After "typedef int foo;", "foo" is just like "int".
joemu@tekecs.UUCP (Joe Mueller) (11/16/84)
> Typedefs are not scoped. They define synonyms for (possibly complicated) > data types. After "typedef int foo;", "foo" is just like "int". Sorry Doug, typedefs are scoped but most pcc compilers botch the handling of them. See K&R pp206 on scoping.
mercer@convex.UUCP (11/21/84)
According to K&R (Appendix A, sec 11.1): "typedef names are in the same class as ordinary identifiers. They may be redeclared in inner blocks, but an explicit type must be given in the inner declaration"