blind

suckless command-line video editing utility
git clone git://git.suckless.org/blind
Log | Files | Refs | README | LICENSE

generate-macros.c (1924B)


      1 /* See LICENSE file for copyright and license details. */
      2 #include <stdint.h>
      3 #include <stdio.h>
      4 
      5 int
      6 main(void)
      7 {
      8 	char *u16 = (char *)&(uint16_t){0x0001};
      9 	char *u32 = (char *)&(uint32_t){0x00010203};
     10 	char *u64 = (char *)&(uint64_t){0x0001020304050607};
     11 	int le16 = (u16[1] == 0 && u16[0] == 1);
     12 	int le32 = (u32[3] == 0 && u32[2] == 1 && u32[1] == 2 && u32[0] == 3);
     13 	int le64 = (u64[7] == 0 && u64[6] == 1 && u64[5] == 2 && u64[4] == 3 &&
     14 	            u64[3] == 4 && u64[2] == 5 && u64[1] == 6 && u64[0] == 7);
     15 	int be16 = (u16[0] == 0 && u16[1] == 1);
     16 	int be32 = (u32[0] == 0 && u32[1] == 1 && u32[2] == 2 && u32[3] == 3);
     17 	int be64 = (u64[0] == 0 && u64[1] == 1 && u64[2] == 2 && u64[3] == 3 &&
     18 	            u64[4] == 4 && u64[5] == 5 && u64[6] == 6 && u64[7] == 7);
     19 
     20 	if (le16)
     21 		printf("#define HOST_ENDIAN_IS_LITTLE_ENDIAN_16\n");
     22 	if (le32)
     23 		printf("#define HOST_ENDIAN_IS_LITTLE_ENDIAN_32\n");
     24 	if (le64)
     25 		printf("#define HOST_ENDIAN_IS_LITTLE_ENDIAN_64\n");
     26 	if (le16 && le32 && le64)
     27 		printf("#define HOST_ENDIAN_IS_LITTLE_ENDIAN\n");
     28 
     29 	if (be16)
     30 		printf("#define HOST_ENDIAN_IS_BIG_ENDIAN_16\n");
     31 	if (be32)
     32 		printf("#define HOST_ENDIAN_IS_BIG_ENDIAN_32\n");
     33 	if (be64)
     34 		printf("#define HOST_ENDIAN_IS_BIG_ENDIAN_64\n");
     35 	if (be16 && be32 && be64)
     36 		printf("#define HOST_ENDIAN_IS_BIG_ENDIAN\n");
     37 
     38 	if (sizeof(float) == 4) {
     39 		unsigned long int a, b;
     40 		a = (unsigned long int)*(uint32_t *)&(float){  (float)(1. / 12.) };
     41 		b = (unsigned long int)*(uint32_t *)&(float){ -(float)(1. / 12.) };
     42 		printf("#define USING_BINARY32 %i\n",
     43 		       a == 0x3daaaaabUL && b == 0xbdaaaaabUL);
     44 	}
     45 	if (sizeof(double) == 8) {
     46 		unsigned long long int a, b;
     47 		a = (unsigned long long int)*(uint64_t *)&(double){  1. / 12. };
     48 		b = (unsigned long long int)*(uint64_t *)&(double){ -1. / 12. };
     49 		printf("#define USING_BINARY64 %i\n",
     50 		       a == 0x3fb5555555555555ULL && b == 0xbfb5555555555555ULL);
     51 	}
     52 
     53 	return 0;
     54 }