This is the mail archive of the gcc@gcc.gnu.org mailing list for the GCC project.


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]
Other format: [Raw text]

C aliasing rules question.


Hi!

gcc 3.3 now warns about

static inline int f_trunc(float f)
{
	f -= 0.5f;
	f += (3<<22);
	return *((int*)&f) - 0x4b400000;
}

to violate C aliasing rules (I see the code is broken as is), is
the following "fix" to the code ok (gcc doesnt warn anymore), as
char* is special wrt aliasing?

static inline int f_trunc(float f)
{
        f -= 0.5f;
        f += (3<<22);
        return *((int*)(char*)&f) - 0x4b400000;
}

Or is this still invalid? Is it at least ok to tell _gcc_ about the
aliasing?

Thanks,

Richard.


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]