Jump to content

  • Log In with Google      Sign In   
  • Create Account

#Actualultramailman

Posted 06 March 2013 - 09:01 PM

char isn't guranteed to be one byte

I remember from somewhere that char is always one byte. Then short <= int <= long <= long long.
 
If you are worrying about this, why not use long or long long instead of int? They might be bigger than int.
 
int endianess(void)
{
        union{
                long long l;
                char c[sizeof(long long)];
        } n = {1};
        return n.c[0];
}
Also check out stdint.h, if the compiler you use supports it.

#2ultramailman

Posted 06 March 2013 - 08:09 PM

char isn't guranteed to be one byte

I remember from somewhere that char is always one byte. Then short <= int <= long <= long long.
 
If you are worrying about this, why not use long or long long instead of int? They might be bigger than int.
 
int endianess(void)
{
        union{
                long long l;
                char c;
        } n = {1};
        return n.c;
}
Also check out stdint.h, if the compiler you use supports it.

#1ultramailman

Posted 06 March 2013 - 08:02 PM

char isn't guranteed to be one byte

I remember from somewhere that char is always one byte. Then short <= int <= long <= long long.

 

If you are worrying about this, why not use long or long long instead of int? They might be bigger than int.

int endianess(void)
{
        union{
                long long l;
                char c;
        } n = {1};
        return n.c;
}

PARTNERS