views:

184

answers:

2

Hi,

I am just starting programming ansi c with gcc under ubuntu (9.04). I get following error messages:

error messages:

main.c:6: error: expected identifier or ‘(’ before ‘/’ token
In file included from /usr/include/stdio.h:75,
                 from main.c:9:
/usr/include/libio.h:332: error: expected specifier-qualifier-list before ‘size_t’
/usr/include/libio.h:364: error: expected declaration specifiers or ‘...’ before ‘size_t’
/usr/include/libio.h:373: error: expected declaration specifiers or ‘...’ before ‘size_t’
/usr/include/libio.h:493: error: expected ‘=’, ‘,’, ‘;’, ‘asm’ or ‘__attribute__’ before ‘_IO_sgetn’
In file included from main.c:9:
/usr/include/stdio.h:314: error: expected declaration specifiers or ‘...’ before ‘size_t’
/usr/include/stdio.h:682: error: expected ‘=’, ‘,’, ‘;’, ‘asm’ or ‘__attribute__’ before ‘fread’
/usr/include/stdio.h:688: error: expected ‘=’, ‘,’, ‘;’, ‘asm’ or ‘__attribute__’ before ‘fwrite’
main.c:12: error: expected identifier or ‘(’ before ‘/’ token

I assume it is a very simple problem, maybe in the configuration of ubuntu or gcc. I am new to programming under linux as well. I googled for help and went through a tutorial but could not find an answer. Thank you!

code:

/* cheat with the preprocessor to skip over missing lines to attempt
   to duplicate the circumstance of the original code */
#line 9
// #include <some_random_header.h>
#include <stdio.h>
#include <math.h>    
int main(int argc, char **argv)
    {
     printf("TestOutput\n");

     return (0);
    }

command:

~/Documents/projects/Trials$ gcc -Wall -ansi  main.c 
+3  A: 

Are you really sure that the code you show is the code you are actually compiling? You get the error:

main.c:12: error: expected identifier or ‘(’ before ‘/’ token

but the code doesn't actually have 12 lines in it.

anon
Nor does it have a `/` token anywhere.
Williham Totland
I commented some lines to have a minimal example. But that turned out to be the problem. Ansi-C does not like "//".
Framester
@Framester The moral to learn is "always post the real code"
anon
yeah, kind of learned it the hard way now...- thanks
Framester
+1  A: 

I used "//" to comment lines, which ansi-c does not like. Thank you all for your input!

Framester
Try -std=c99 instead.
Bastien Léonard
-1: This should be a comment, not an answer.
Paul R
Even though, it was the answer to my problem?
Framester
Welcome to stackoverflow.com ;-)
James Morris
+1 to encourage documenting the answer to the actual problem.
RBerteig