3 ms·
% cat test.c main () { int x x=1 } % gcc test.c test.c:1:1: warning: type specifier missing, defaults to 'int' [-Wimplicit-int]
by lisper 2y ago
% cat test.c
main () {
int x
x=1
}
% gcc test.c
test.c:1:1: warning: type specifier missing, defaults to 'int' [-Wimplicit-int]
main () {
^
test.c:2:8: error: expected ';' at end of declaration
int x
^
;
1 warning and 1 error generated.
- cess11 2y agoI added int to the main declaration to clean the irrelevant warning, and I get this: tst.c: In function ‘main’: tst.c:3:5: error: expected ‘=’, ‘,’, ‘;’, ‘asm’ or ‘__attribute__’ before ‘x’ 3 | x=1 | ^ tst.c:3:5: error: ‘x’ undeclared (first use in this function) tst.c:3:5: note: each undeclared identifier is reported only once for each function it appears in tst.c:3:8: error: expected ‘;’ before ‘}’ token 3 | x=1 | ^ | ; 4 | } | ~ gcc (Debian 12.2.0-14) 12.2.0 I get three errors, all on line 3 rather than 2, and as the first of them says, there are at least four alternatives for resolution besides semicolon. Full code after adding type to main, including linter message from c.vim: 1 int main () { 2 int x E 3 x=1 /\* E: 'x' undeclared (first use in this function) 4 } .