Compatibility With K&R C - Texas Instruments TMS320C2x User Manual

Optimizing c compiler digital signal processor
Hide thumbs Also See for TMS320C2x:
Table of Contents

Advertisement

Compatibility with K&R C
5.8 Compatibility with K&R C
5-14
The ANSI C language is a superset of the de facto C standard defined in Ker-
nighan and Ritchie's The C Programming Language. Most programs written
for other non-ANSI compilers correctly compile and run without modification.
There are subtle changes, however, in the language that can affect existing
code. Appendix C in The C Programming Language (second edition, referred
to in this manual as K&R) summarizes the differences between ANSI C and
the first edition's C standard (the first edition is referred to in this manual as
K&R C).
To simplify the process of compiling existing C programs with the 'C6000 ANSI
C compiler, the compiler has a K&R option (−pk) that modifies some semantic
rules of the language for compatibility with older code. In general, the −pk op-
tion relaxes requirements that are stricter for ANSI C than for K&R C. The −pk
option does not disable any new features of the language such as function pro-
totypes, enumerations, initializations, or preprocessor constructs. Instead,
−pk simply liberalizes the ANSI rules without revoking any of the features.
The specific differences between the ANSI version of C and the K&R version
of C are as follows:
The integral promotion rules have changed regarding promoting an
-
unsigned type to a wider signed type. Under K&R C, the result type was
an unsigned version of the wider type; under ANSI, the result type is a
signed version of the wider type. This affects operations that perform dif-
ferently when applied to signed or unsigned operands; namely, compari-
sons, division (and mod), and right shift:
unsigned short u;
int i;
if (u < i) ...
*/
ANSI prohibits combining two pointers to different types in an operation.
-
In most K&R compilers, this situation produces only a warning. Such
cases are still diagnosed when −pk is used, but with less severity:
int *p;
char *q = p; /* error without −pk, warning with −pk */
Even without −pk, a violation of this rule is a code-E (recoverable) error.
You can use −pe, which converts code-E errors to warnings, as an alterna-
tive to −pk.
External declarations with no type or storage class (only an identifier) are
-
illegal in ANSI but legal in K&R:
a;
/* SIGNED comparison, unless −pk used
/* illegal unless −pk used */

Advertisement

Table of Contents
loading
Need help?

Need help?

Do you have a question about the TMS320C2x and is the answer not in the manual?

Subscribe to Our Youtube Channel

This manual is also suitable for:

Tms320c2xxTms320c5x

Table of Contents