Home >Backend Development >C++ >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 :
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!