get a struct member pointer

Daniel Keep daniel.keep.lists at gmail.com
Mon Feb 16 05:04:01 PST 2009



bearophile wrote:
> Daniel Keep:
>> void lookup(T)(T[] s, size_t offset)
>> {
>>   char[] text = *cast(char[]*)(cast(void*)(&s[0]) + offset);
>> }
> 
> I am learning still this topic, but can't this create an aliasing problem, as in C?

Oh I really doubt the above is safe.  But it's the only way I can think
of to access a given struct field at runtime.

> http://www.cellperformance.com/mike_acton/2006/06/understanding_strict_aliasing.html

Heads up, Google is flagging the above site as doing drive-by
installation of malicious software.

Report here:
http://safebrowsing.clients.google.com/safebrowsing/diagnostic?client=Firefox&hl=en-GB&site=http://www.cellperformance.com/mike_acton/2006/06/understanding_strict_aliasing.html

> Bye,
> bearophile


More information about the Digitalmars-d-learn mailing list