Jump to content

  • Log In with Google      Sign In   
  • Create Account

FREE SOFTWARE GIVEAWAY

We have 4 x Pro Licences (valued at $59 each) for 2d modular animation software Spriter to give away in this Thursday's GDNet Direct email newsletter.


Read more in this forum topic or make sure you're signed up (from the right-hand sidebar on the homepage) and read Thursday's newsletter to get in the running!


#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