Skip to content

Instantly share code, notes, and snippets.

@panzi
Created January 12, 2013 17:45
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save panzi/4519534 to your computer and use it in GitHub Desktop.
Save panzi/4519534 to your computer and use it in GitHub Desktop.
fourcc as uint32_t
#include <stdint.h>
#include <endian.h>
#define _MAGIC_FROM_CHARS(C1,C2,C3,C4) (uint32_t)(((C1) << 24) | ((C2) << 16) | ((C3) << 8) | (C4))
#if __BYTE_ORDER == __LITTLE_ENDIAN
# define MAGIC_FROM_CHARS(C1,C2,C3,C4) _MAGIC_FROM_CHARS(C4,C3,C2,C1)
#elif __BYTE_ORDER == __BIG_ENDIAN
# define MAGIC_FROM_CHARS(C1,C2,C3,C4) _MAGIC_FROM_CHARS(C1,C2,C3,C4)
#elif __BYTE_ORDER == __PDP_ENDIAN
# define MAGIC_FROM_CHARS(C1,C2,C3,C4) _MAGIC_FROM_CHARS(C3,C4,C1,C2)
#else
# error unsupported byte order
#endif
#define MAGIC(S) MAGIC_FROM_CHARS((S)[0], (S)[1], (S)[2], (S)[3])
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment