Versions Compared

Key

  • This line was added.
  • This line was removed.
  • Formatting was changed.

...

According to the WG14 document:

     Given       Given an integer expression E, the derived type T of E is determined as follows:

                         - if E is a sizeof expression, then T is the type of the operand of the expression;

                         - otherwise, if E is an identifier, then T is the derived type of the expression last used to store a value in E;

                         - otherwise, if the derived type of each of E's subexpressions is the same, then T is that type;

                         - otherwise, the derived type is an unspecified character type compatible with any of char, signed char, and unsigned char.Note:

  • The first rule from the above definition is applied to non-compliant code/compliant solution 2 and 4 in this page to calculate the derived type of expression 'n' is those examples.

Effective size of a pointer is the size of the object to which it points.

...

Effective type of an object is is defined as either its declared type or (in case its type hasn't been declared) the effective type of the value assigned to it. In the examples below, we have used terms like 'effective type of pointer p' which implies that if the type of 'p' has been declared (eg: char *p) then that type (in this case char) is the effective type of the pointer. If the type is not declared (eg: void *p) and then the pointer is assigned a value (p = obj), then the effective type of 'p' is the effective type of 'obj'.

Noncompliant Code Example

...

Note: A possibility of this code being safe would be on architectures where sizeof (*int) is equal to sizeof (*float).

Compliant Solution

...