Examples of code violating of the standards

The respect of the standards of Programmation is a constraint in the data-processing languages. Some program S not respecting these standards can sometimes have a correct but incorrect behavior in other cases.

If one considers the case of the C the standard specifies two types of behaviors according to the violations considered:

  • behavior not specified : The standard describes the possible behaviors without specifying which will be used ( unspecified behavior in English).
  • unspecified behavior : no specification, the Compiler and the environment of execution are free to impose a behavior including having a random behavior ( undefined behavior in English).

To use a behavior not specified in a program is possible if:

  • the Mise in work of the standard specifies in its documentation which behavior will be used.
  • the author of the program decides that it will be used only with this implementation precise of the standard.

Obviously in this case the program considered will not be portable in other environments.

Code having a behavior not specified in C

#include int hand (void) { int has = 0; printf (" %d %d\n", has, ++a); return 0; }

The order of evaluation of the parameters at the time of a call of function is not specified in the standard describing the language C, also the Compilateur can evaluate this fragment of code in several ways different. For example:

int J = has; int K = J + 1; printf (" %d %d\n", J, K);

will post: 0 1

or:

int J = has + 1; int K = J; printf (" %d %d\n", J, K);

will post: 1 1

Code having an unspecified behavior in C

int hand (void) { double has; double * Pa = & has; float * C; C = (float *) Pa; return 0; }

Conversion between two pointers towards types which have conditions of potentially different alignments produces an unspecified result in C.

Random links:Doctor Mabuse | The Ear trumpet | Public records (Hungary) | Paul Mazurkiewicz | Ultramar Diamond Shamrock | 34_AVANT_JÉSUS_CHRIST