Exceptions to C Being a Subset of C
While it's commonly stated that C is a subset of C , this assertion is not entirely accurate. Differences emerge when comparing specific versions of C and C .
C89 vs. C Differences
-
No Tentative Definitions: C doesn't allow redeclaring variables with the same name without a definition in between.
-
Different Array Type Compatibility: C distinguishes between arrays of a specific size (e.g., int a[1]) and arrays with unspecified size (e.g., int (*ap)[]), whereas C allows them to be compatible.
-
No K&R Function Declaration Style: C requires a different syntax for function definitions, disallowing the old K&R style (e.g., int b(a) int a; { }).
-
Nested Struct Scope Differences: In C , a nested struct is treated as a class-level declaration, making it inaccessible outside the enclosing struct.
-
No Default int Type: In C , auto variables require explicit type specifiers, unlike in C where int is assumed by default.
C99 vs. C Differences
C99 introduces additional deviations from strict C compatibility:
-
Array Dimension Restrictions: C99 disallows certain special characters in specifying array dimensions of function parameters.
-
Absence of Variable Length Arrays: Variable-length arrays, declared using non-constant expressions as sizes, are not supported in C .
-
No Flexible Array Members: C99's flexible array members, where the size can be specified at run-time, are incompatible with C .
-
Lack of restrict Qualifier: C 's restrict qualifier, used for optimization purposes, is not available in C99.
The above is the detailed content of Is C Truly a Subset of C : Exploring Key Differences and Exceptions?. For more information, please follow other related articles on the PHP Chinese website!