c - 老版本的C语法差异?

标签 c

对于一个非常具体的项目,我需要用 C 编写一个 16 位程序,我在 MS-DOS 中使用 Microsoft QuickC 来编写这个程序。现在我很确定我的程序的语法是正确的,但程序无法编译,它认为我有语法错误。这是因为 MS-DOS 中的 C 编译器使用具有不同语法的旧版本 C 吗?

#include<stdio.h>

main()
{
   printf("Hello World!");
}

即使是那个简单的 hello world 程序也无法编译和运行。

最佳答案

你应该将 main 定义为 int

因此将您的代码更改为:

  int main() {    // define main as an int returning function

       // your code

       return 0; // Also make sure you have return statement in main
  }

它会编译

这是它在标准中的说法:

1 程序启动时调用的函数名为main。该实现没有为此函数声明原型(prototype)。 它应该用 int 的返回类型定义:

int main(void) { /* ... */ } 

编辑:

好的,从您的评论来看...您现在收到此错误:

   C1024: cannot open include file 'stdio.h'

这是微软的原因和解决方案:

http://support.microsoft.com/kb/97809

关于c - 老版本的C语法差异?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/19763626/

相关文章:

c - glob(使用唯一前缀)是否比 readdir 更快?

c - 指向结构体中函数的指针

c - getc(stdin) 后程序停止工作

c - struct 中的匿名 union 不在 c99 中?

c - 为什么我不能在函数中第二次声明结构?

c - 动态数组 : Separating Numbers into Even and Odd Using C

任何人都可以解释为什么这部分代码会出现运行时错误吗?

c++ - c/c++预处理器: how to ensure that correct file is included

c - 请解释这个对齐错误

C:尝试在屏幕上打印数据后出现段错误