b.c:
int main() {
a = 1;
return a;
}
clang.exe -std=c89 b.c
b.c:2:3: error: use of undeclared identifier ‘a’
a = 1;
^
b.c:3:10: error: use of undeclared identifier ‘a’
return a;
^
2 errors generated.
For c89, why variable a is not made as an implicit int?
Thanks,
Hongbo
Because that's not what C89 says. "implicit int" was for functions, not
variables.
-- James
Thanks! Are you aware of any rule (or code correction in clang) that can automatically add a type (or correct a type) to a variable? Any example and command line?
its not very helpfull to ask micro-questions - give a more fully description of you're trying to archive in the end - not what you think whats needed to get to the point
would help alot
It is for globals, arguments, function return types. But not for
auto variables.
Joerg
I want to do some simple type inference on variables, if their types are missing. For example, if there is a statement like “a=1” or “a=”hello””, identifier a is automatically set to int or char*. Does clang has examples/code for similar situations?
Thanks!