在Ubuntu下使用ansi-c和gcc的初学者问题/错误

2ledvvac  于 2023-03-22  发布在  其他
关注(0)|答案(2)|浏览(143)

我刚开始在ubuntu(9.04)下用gcc编写ansi c。我得到以下错误消息:

错误消息:

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

我认为这是一个非常简单的问题,也许是在ubuntu或gcc的配置中。我也是linux下编程的新手。我在谷歌上寻求帮助,并通过tutorial,但找不到答案。谢谢!

代码:

/* 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);
    }

命令:

~/Documents/projects/Trials$ gcc -Wall -ansi  main.c
zujrkrfu

zujrkrfu1#

你真的确定你显示的代码是你实际编译的代码吗?你会得到错误:

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

但代码实际上并没有12行。

ifsvaxew

ifsvaxew2#

我用“//”来注解行,这是ansi-c不喜欢的。谢谢大家的意见!

相关问题