DOC HOME SITE MAP MAN PAGES GNU INFO SEARCH PRINT BOOK
 
Complying with standard C

The Kernighan and Ritchie C rearrangement license

The Kernighan and Ritchie C rearrangement license applies to the above expression because addition is mathematically commutative and associative. To distinguish between regular parentheses and the actual grouping of an expression, the left and right curly braces will designate grouping. The three possible groupings for the expression are

   i = { {*++p + f()} + g() };
   i = { *++p + {f() + g()} };
   i = { {*++p + g()} + f() };
all of which are valid given Kernighan and Ritchie C rules. Moreover, all of these groupings are valid even if the expression were written instead, for example, in either of these ways:
   i = *++p + (f() + g());
   i = (g() + *++p) + f();
If this expression is evaluated on an architecture for which either overflows cause an exception or addition and subtraction are not inverses across an overflow, these three groupings will behave differently if one of the additions overflows.

For such expressions on these architectures, the only recourse available in Kernighan and Ritchie C was to split the expression to force a particular grouping. The following are possible rewrites that respectively enforce the above three groupings.

   i = *++p; i += f(); i += g();
   i = f();  i += g(); i += *++p;
   i = *++p; i += g(); i += f();

Next topic: The ANSI C rules
Previous topic: Definitions

© 2005 The SCO Group, Inc. All rights reserved.
SCO OpenServer Release 6.0.0 -- 02 June 2005