ansi C standard summary
Doug Moen
kdmoen at watcgl.UUCP
Wed Mar 6 16:19:01 AEST 1985
This is an informal list of the differences I have been able to find
between Unix C (actually VAX PCC) and the language described in
the Feb 11 draft version of the Ansi C Standard.
The list should be considered neither complete nor authoritative.
Doug Moen, watmath!watcgl!kdmoen
University of Waterloo Computer Graphics Lab
-----
A set of trigraphs have been defined to allow C programs to be entered
on terminals that don't support the full ASCII character set [B.2.1]:
??= #
??( [
??/ \
??) ]
??' ^
??< {
??! |
??> }
??- ~
These trigraphs are even interpreted within string constants,
so that "??=" is identical to "#". [B.1.1.2]
\ at the end of a line joins 2 lines together. You could split an
identifier or a keyword over 2 lines if you wanted to. [B.1.1.2]
summary of new keywords:
const signed volatile
new character escape sequences:
\a alert (^G in ascii)
\v vertical tab
\? ?
\xddd hex constant
A strictly conforming program must assume that only 6 characters are
significant in an external identifier, monocase.
[C.1.2, A.7] (Internal identifiers are guaranteed to be significant in
their first 31 characters, dual case).
"External identifiers beginning with an underscore, and all identifiers
beginning with 2 underscores, are reserved for use by the implementation,
and must not be used by a program, except to specify implementation-defined
values." [B.2.4.2]
floating point numbers:
'long double' is a new type.
Floating point constants may be suffixed with f F l or L, making them of
type 'float' or 'long double'.
If a and b have type 'float', then it is permissible to evaluate 'a + b'
in single precision arithmetic, yielding a 'float' result instead of
a 'double'.
integers:
'signed char' is a new type. Whether plain 'char' is treated as 'signed char'
or 'unsigned char' is implementation defined.
Integer constants may be suffixed by u or U, l or L, or both, making them
of type unsigned, long, or unsigned long.
Chars must be at least 8 bits long, shorts 16, and longs 32. [B.2.4.1]
string literals:
"foo" "bar" is equivalent to "foobar".
#define ROGUEDIR "/usr/games/lib/rogue"
f = fopen(ROGUEDIR "/scorefile", "r");
String literals may not be modified (they have type 'array of const char').
Identical string literals need not be distinct.
An object declared 'const' cannot be assigned to.
/*
* This is not quite a substitute for #define MAGIC ...
* since MAGIC is assigned storage, and &MAGIC is allowed.
*/
const int MAGIC = 42;
/*
* Tell the compiler to put this in ROM (an embedded application)
* or the text section (Unix):
*/
const struct foo MyTable[] = { ...
const int *variablePointerToAConstantValue;
int *const constantPointerToAVariableValue;
An object declared 'volatile' may be modified in ways unknown to the
compiler. This allows you to reliably access device registers and
shared memory, even if the compiler performs global optimization.
'void *' is a new type -- a generic pointer.
Function prototypes:
extern int foo();
declares an external function called 'foo' returning 'int', with no
information about its parameters.
double sqrt(double);
declares a function with one parameter of type 'double'. When the
function is called, the argument is automatically converted to type
double if necessary.
int printf(const char *format, ...);
printf has 1 typechecked argument, and 0 or more unchecked arguments.
int bar(void);
bar has no arguments.
Unary + is a new operator.
Constant expressions may contain casts.
The identifiers introduced by an enumerated type are 'int' constants,
and may appear wherever such are permitted. (This means you can now
index an array with an enumerated type constant, something which PCC
disallows).
Unions may be initialized. The initializer initializes the member
that appears first in the declaration of the union.
Auto aggregates may be initialized.
There may be spaces and tabs before the # starting a preprocessor directive.
There may be white space between a macro name and the ( )'s enclosing
its actual parameter list (Unix cpp disallows this).
A macro definition may contain the name of the macro being defined.
It won't be recursively expanded.
'token ## token' concatenates 2 tokens.
Within a macro definition, # formalParameter is replaced by a string
literal made from the parameter.
#define debug(s, t) printf("x" #s "= %d, x" #t "= %s", \
x ## s, x ## t)
debug(1, 2)
results in
printf("x" "1" "= %d, x" "2" "= %s", x1, x2)
or, after concatenation of the unit string literals,
printf("x1= %d, x2=%s", x1, x2)
The macro names __LINE__ and __FILE__ expand to the current line and file.
"No other macro names are predefined." [C.8.2]
"An implementation may define macros whose names begin with two or more
underscores, even if no headers are explicitly included." [D.1.2]
new preprocessing directives:
#elif constant-expression
means 'else if'.
#pragma implementation-dependent-string
A pragma does something implementation dependent. Any pragma not recognized
by the compiler is ignored.
More information about the Comp.lang.c
mailing list