Re: Identifying a structure by reading it's first field.
- From: Chris Vine <chris cvine freeserve co uk>
- To: Ernie Wright <erniew comcast net>
- Cc: gtk-app-devel-list gnome org
- Subject: Re: Identifying a structure by reading it's first field.
- Date: Sat, 2 Jun 2012 16:30:23 +0100
On Sat, 02 Jun 2012 09:10:06 -0400
Ernie Wright <erniew comcast net> wrote:
On 6/2/2012 6:16 AM, Chris Vine wrote:
You are probably also interested in the strict aliasing rule, [...]
This is an alarmingly often overlooked rule.
In part because it wasn't in the standard prior to C99, which isn't
supported to the degree C90 is.
It was in C89 - §6.3:
"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."
It is the fifth bullet point which permits your usage. Not many
1990-vintage compilers used strict aliasing for optimization, but most
(all?) now do with a sufficiently high optimizing level.
Chris
[
Date Prev][
Date Next] [
Thread Prev][
Thread Next]
[
Thread Index]
[
Date Index]
[
Author Index]