ANSI C 89 和 C++ 支持的 C 有什么区别?
我知道 ANSI C 89 和 C++ 支持的 C 之间存在一些差异。
例如,在 ANSI C 89 中,您应该在块的第一行声明变量。
或者当你想声明struct
变量时,你应该使用struct
关键字(例如struct Student std1;
)。
或 // 对于注释无效,您应该使用 /**/ 在 ANSI C 89 中进行注释。
例如,此 C 代码在 ANSI C 89 中无效:
struct student
{
char* name;
};
enum number
{
ODD,
EVEN
};
void test()
{
printf("Hello world!");
int a, b; // Not valid in ANSI C 89, variables should declare at first line of blocks.
student std1; // Not valid. It should be: struct student std1;
struct student std2; // Valid.
number n1 = ODD; // Not valid.
enum number n2 = EVEN; // Valid.
}
我想使用 ANSI C 89 开发一个应用程序,我的问题是:
ANSI C 89 和 C++ 支持的 C 有什么区别?
I know there are some difference between ANSI C 89 and C that supports by C++.
for example in ANSI C 89, you should declare variables at first line of blocks.
or when you want to declare struct
variables, you should use struct
keyword (eg struct student std1;
).
or // is not valid for commenting and you should use /**/ for commenting in ANSI C 89.
for example this C code is not valid in ANSI C 89:
struct student
{
char* name;
};
enum number
{
ODD,
EVEN
};
void test()
{
printf("Hello world!");
int a, b; // Not valid in ANSI C 89, variables should declare at first line of blocks.
student std1; // Not valid. It should be: struct student std1;
struct student std2; // Valid.
number n1 = ODD; // Not valid.
enum number n2 = EVEN; // Valid.
}
I want to develope an application using ANSI C 89 and my question is:
What is the difference between ANSI C 89 and C that supports by C++?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
C++98/03 的 C 子集是以 C89 为模型的(显然,因为当时 C99 还没有推出); C++11 的版本是仿照 C99 的。尽管如此,这些语言还是有很大不同的,而且 C++ 的 C 子集与 C 语言并不相同
。您本质上是在问“C++ 和 C 之间有什么区别”,这实际上不是一个合适的问题。
(例如,
sizeof('a')
在 C 和 C++ 中是不同的,因此,如果您使用 MSVC++,了解 C++ 建模所依据的 C 标准对您没有任何帮助) 。The C subset of C++98/03 is modeled on C89 (obviously, since C99 wasn't out at the time); that of C++11 is modeled on C99. Nonetheless, the languages are quite different and the C subset of C++ isn't the same as the language C.
You're essentially asking "what's the difference between C++ and C", which isn't really a suitable question.
(For example,
sizeof('a')
is different in C and in C++, so if you're using MSVC++, knowing the C standard on which C++ was modeled doesn't help you at all).