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 23:43 ID:mnQcz8y0

It still doesn't make any sense to do it at runtime, since the machine isn't going to change its endianness depending on whether it's executing the compiler or your program.

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