-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathmain6.c
42 lines (34 loc) · 1.34 KB
/
main6.c
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
// gcc -O2 -Wall -o main6 main6.c
// demonstrate compile_assert checking a TGA image data file header is valid
// the header is 18 bytes, and 4 pixels are another 16 bytes
#include "compile_assert.h"
#include <stdio.h>
#include <stdint.h>
// Note: buffer must be const
// 18+16 bytes
const uint8_t tga_file[] = {
0x00, // ID length
0x00, // Color map type
0x02, // Image type (truecolor)
0x00, 0x00, // Color map specification (offset)
0x00, 0x00, // Color map specification (length)
0x00, // Color map depth
0x00, 0x00, // X-origin
0x00, 0x00, // Y-origin
0x02, 0x00, // Image width (2 pixels)
0x02, 0x00, // Image height (2 pixels)
0x20, // Pixel depth (32 bits per pixel: 8 bits for B, 8 bits for G, 8 bits for R, 8 bits for A)
0x00, // Image descriptor
0x00, 0xFF, 0xFF, 0x00, // 32bit pixel
0x00, 0xFF, 0xFF, 0x00, // 32bit pixel
0x00, 0xFF, 0xFF, 0x00, // 32bit pixel
0x00, 0xFF, 0xFF, 0x00, // 32bit pixel
0x11 // this is a bug, not meant to be here, just for the compile_assert
};
int main()
{
compile_assert(tga_file[2] == 0x01, "Must be truecolor"); // will fire, as must be 0x02
compile_assert(sizeof(tga_file) == (16+18), "must be the right size"); // will fire as must remove extra byte
printf("%d\n", tga_file[0]);
return 0;
}