??? 09/19/06 15:09 Read: times |
#124571 - Undeclared Variables Responding to: ???'s previous message |
Actually, that's not true in 'C'
In 'C', all symbols defined at file scope are automatically global unless you specifically restrict them to file scope by using 'static'. If a symbol is undeclared, a 'C' compiler will just assume that it's an extern int. If the Linker later finds a public definition of the symbol name, it will make the link. If you're lucky, you'll get away with it. But this gives no check that the public definition found matches the external declaration assumed... This is really interesting. I know that C assumes extern int for undeclared functions. This program, for example, compiles without problems, even though a() is not declared. void main() { int i; i = a(); }But for simple variables, both of the compilers I have access to at the moment give a fatal (not just a warning) "undeclared identifier" error. For example, void main() { int i; i = j; }simply won't compile because 'j' is not declared. Am I missing something here? Or did maybe pre-ANSI C make the assumption you're talking about? Or ??? -- Russ PS: Thanks to everyone who reminded me about the 'static' modifier. |