Return Styles: Pseud0ch, Terminal, Valhalla, NES, Geocities, Blue Moon. Entire thread

C Determine endianess

Name: Anonymous 2007-06-27 10:43 ID:Uo4E/xRf

I wrote it and i edited wikipedias article which had a terrible code and added mine, but i'm still not sure about my code, is it SCALABLE ENOUGH?

#include <stdio.h>

int main() {

        union {
                int s;
                char c[sizeof(int)];
        } un;
        const char *endianess[[] = { "big endian", "little endian" };

        un.s = (~(int)0) ^ (~(char)0);
        puts(endianess[!un.c[0]]);

        return 0;
}

Name: Anonymous 2007-06-27 20:46 ID:Heaven

>>15
What kinds of shitty compiler needs you to tell it the byteorder of the current machine?

(Also, show me a 'scripting' language that allows pointer/union tricks, but doesn't have a constant that tells you the byteorder.)

Newer Posts
Don't change these.
Name: Email:
Entire Thread Thread List