M
Marco Devillers
Hi all, a short question.
I wrote a compiler which compiles to C and has a garbage collector
written in C. The garbage collector assumes that nodes in memory are
arrays of integers or pointers (I use the default integer of pointer
size type for that).
However, sometimes, terminal nodes may hold other values, such as
floats, doubles, etc. Naturally, I cast these then to the correct
type, so a intptr_t* becomes a float*. Of course, this is unspecified
behavior according to the C standard, so I need to compile with the -
fno-strict-aliasing switch in gcc.
I want to rewrite my code such that I don't need that switch anymore,
i.e., I want to end up with portable code.
My question: What is the correct manner to rewrite this code?
I know there's an exception to strict aliasing, i.e., the char
pointer. Should I redefine the node pointer type as char*, or is it
sufficient to cast intptr_t* to char* and then to float* (can I use a
char* as an intermediate to trick the C type system)?
Thanks all,
Marco
I wrote a compiler which compiles to C and has a garbage collector
written in C. The garbage collector assumes that nodes in memory are
arrays of integers or pointers (I use the default integer of pointer
size type for that).
However, sometimes, terminal nodes may hold other values, such as
floats, doubles, etc. Naturally, I cast these then to the correct
type, so a intptr_t* becomes a float*. Of course, this is unspecified
behavior according to the C standard, so I need to compile with the -
fno-strict-aliasing switch in gcc.
I want to rewrite my code such that I don't need that switch anymore,
i.e., I want to end up with portable code.
My question: What is the correct manner to rewrite this code?
I know there's an exception to strict aliasing, i.e., the char
pointer. Should I redefine the node pointer type as char*, or is it
sufficient to cast intptr_t* to char* and then to float* (can I use a
char* as an intermediate to trick the C type system)?
Thanks all,
Marco