Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Do C89 or C++03 define strict aliasing rules?

Tags:

c++

c

I've seen several assertions that C89 and C++03 define strict aliasing rules. I, however, cannot find that particular bit in the standard. My understanding was that strict aliasing rules were added in C99.

like image 300
Billy ONeal Avatar asked Jun 29 '11 00:06

Billy ONeal


1 Answers

This text is present in C89, §3.3 EXPRESSIONS:

An object shall have its stored value accessed only by an lvalue that has one of the following types:

  • the declared type of the object,

  • a qualified version of the declared type of the object,

  • a type that is the signed or unsigned type corresponding to the
    declared type of the object,

  • a type that is the signed or unsigned type corresponding to a
    qualified version of the declared type of the object,

  • an aggregate or union type that includes one of the aforementioned
    types among its members (including, recursively, a member of a
    subaggregate or contained union), or

  • a character type.

Violation of a "shall" constraint leads to undefined behaviour, so a set of allowed aliasing rules can be derived from this text.

like image 122
caf Avatar answered Sep 28 '22 04:09

caf