[cairo] Re: Speeding up _cairo_fixed_from_double

Nicholas Miell nmiell at gmail.com
Mon Oct 30 16:35:17 PST 2006


On Mon, 30 Oct 2006 16:10:31 -0800, Nicholas Miell wrote:

> On Mon, 30 Oct 2006 15:58:12 -0500, Behdad Esfahbod wrote:
> 
>> Cannot reproduce.
>> 
>> This code:
>> 
>> void
>> main (void)
>> {
>>   int endian = 1;
>>   if (*(char *) &endian)
>>     return '\154'; /* 'l' */
>>   else
>>     return '\102'; /* 'B' */
>> }
>> 
> 
> Try "int main(void)" instead of "void main(void)".
> 
> Compiling with -Wall helps, too. :)
> 
> And for little one-off tests like this, you shouldn't use main (on x86,
> anyway -- gcc inserts extra stack alignment ops which confuses the issue).

Sorry to reply to my own mail, but...

This is http://gcc.gnu.org/bugzilla/show_bug.cgi?id=26069

The following does the right thing (on gcc (GCC) 4.1.1 20061011 (Red Hat
4.1.1-30), anyway):
int isBigEndian_union()
{
        union { unsigned u; char c[4]; } x = { .u = 1 };
	return x.c[0];
}

And the moral of the story is that relying on the compiler to do anything
beyond the absolute minimum interpretation of the standard is foolish.

Hope that helps.



More information about the cairo mailing list