Hacker Newsnew | past | comments | ask | show | jobs | submitlogin

I 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 }

.


Guidelines | FAQ | Lists | API | Security | Legal | Apply to YC | Contact

Search: