Home >Backend Development >C++ >What C99 and C Code Differences Cause Compilation Errors?

What C99 and C Code Differences Cause Compilation Errors?

Barbara Streisand
Barbara StreisandOriginal
2024-12-16 09:23:11576browse

What C99 and C   Code Differences Cause Compilation Errors?

C99 and C Compatibility Exceptions

While C is generally a subset of C , certain nuances in the C language prohibit the direct compilation of some valid C code. Here are some key differences to consider:

1. No Tentative Definitions

C allows multiple declarations of variables with the same name, but C does not. Consequently, the following code, which is valid in C, will not compile in C :

int n;
int n; // ill-formed: n already defined

2. Incompatible Array Types

In C, arrays can be declared with either int[] or int[N] syntax. However, C treats these differently. The following code, which is valid in C, will raise an error in C :

int a[1];
int (*ap)[] = &a; // ill-formed: a does not have type int[]

3. K&R Function Definition Style Disallowed

C supports the K&R style of function definition, but C does not. The following code, which is valid in C, will not compile in C :

int b(a) int a; { } // ill-formed: grammar error

4. Nested Struct Scope Differences

In C, nested structs have file scope, while in C , they have class scope. This means that the following code, which is valid in C, will not compile in C :

struct A { struct B { int a; } b; int c; };
struct B b; // ill-formed: b has incomplete type (*not* A::B)

5. No Default int

C does not allow defaulting integer variables to int, unlike C. Therefore, the following code, which is valid in C, will raise an error in C :

auto a; // ill-formed: type-specifier missing

Additional Exceptions in C99

In addition to these exceptions, C99 introduces further incompatibilities with C :

  • No special handling of declaration specifiers in array dimensions of parameters.
  • No variable length arrays.
  • No flexible array member.
  • No restrict qualifier for aliasing analysis.

The above is the detailed content of What C99 and C Code Differences Cause Compilation Errors?. For more information, please follow other related articles on the PHP Chinese website!

Statement:
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn