Handmade Hero»Forums»Code
Jordan Trainor
2 posts
Confusion when typedefing ints and uints ect
Edited by Jordan Trainor on
To start I have my win32_handmade.cpp which contains all the typedefs at the very top of my code.

 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
#include <math.h>
#include <stdint.h>

#define internal static 
#define local_persist static 
#define global_variable static

#define Pi32 3.14159265359f
typedef int8_t int8;
....

typedef uint8_t uint8;
....

typedef float real32;
typedef double real64;

#include "handmade.h"
#include "handmade.cpp"

#include <windows.h>
#include <stdio.h>
#include <malloc.h>
#include <xinput.h>
#include <dsound.h>


after the typedefs I include handmade.h and handmade.cpp and finally include everything else needed.

win32_handmade.cpp uses all the defines correctly and does not complain about anything.

handmade.cpp and handmade.h both complain about the defines such as
1
internal; uint8

with Error: 'uint8' is undefined and Error: this declaraation has no storage class of type specifier

one simple fix is to define the typedefs in handmade.h and it is available everywhere but it should work without doing that so I decided to make a new project and use the sourcecode from the preorder.

It still gives all the errors in handmade.h and handmade.cpp any ideas?

Here is the full output on build

 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
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
1>------ Build started: Project: Handmade Hero, Configuration: Debug x64 ------
1>  win32_handmade.cpp
1>win32_handmade.cpp(326): warning C4244: 'initializing' : conversion from 'WPARAM' to 'uint32', possible loss of data
1>  handmade.cpp
1>\handmade.h(35): error C2143: syntax error : missing ';' before '*'
1>\handmade.h(35): error C4430: missing type specifier - int assumed. Note: C++ does not support default-int
1>\handmade.h(38): error C2144: syntax error : 'void' should be preceded by ';'
1>\handmade.h(38): error C4430: missing type specifier - int assumed. Note: C++ does not support default-int
1>handmade.cpp(12): error C2144: syntax error : 'void' should be preceded by ';'
1>handmade.cpp(12): error C4430: missing type specifier - int assumed. Note: C++ does not support default-int
1>handmade.cpp(12): error C2086: 'int internal' : redefinition
1>          \handmade.h(38) : see declaration of 'internal'
1>handmade.cpp(14): error C2065: 'local_persist' : undeclared identifier
1>handmade.cpp(14): error C2146: syntax error : missing ';' before identifier 'real32'
1>handmade.cpp(14): error C2065: 'real32' : undeclared identifier
1>handmade.cpp(14): error C2146: syntax error : missing ';' before identifier 'tSine'
1>handmade.cpp(14): error C2065: 'tSine' : undeclared identifier
1>handmade.cpp(15): error C2065: 'int16' : undeclared identifier
1>handmade.cpp(15): error C2146: syntax error : missing ';' before identifier 'ToneVolume'
1>handmade.cpp(15): error C2065: 'ToneVolume' : undeclared identifier
1>handmade.cpp(18): error C2065: 'int16' : undeclared identifier
1>handmade.cpp(18): error C2065: 'SampleOut' : undeclared identifier
1>handmade.cpp(18): error C2039: 'Samples' : is not a member of 'game_sound_output_buffer'
1>         \handmade.h(32) : see declaration of 'game_sound_output_buffer'
1>handmade.cpp(24): error C2065: 'real32' : undeclared identifier
1>handmade.cpp(24): error C2146: syntax error : missing ';' before identifier 'SineValue'
1>handmade.cpp(24): error C2065: 'SineValue' : undeclared identifier
1>handmade.cpp(24): error C2065: 'tSine' : undeclared identifier
1>handmade.cpp(24): error C3861: 'sinf': identifier not found
1>handmade.cpp(25): error C2065: 'int16' : undeclared identifier
1>handmade.cpp(25): error C2146: syntax error : missing ';' before identifier 'SampleValue'
1>handmade.cpp(25): error C2065: 'SampleValue' : undeclared identifier
1>handmade.cpp(25): error C2065: 'SineValue' : undeclared identifier
1>handmade.cpp(25): error C2065: 'ToneVolume' : undeclared identifier
1>handmade.cpp(26): error C2065: 'SampleOut' : undeclared identifier
1>handmade.cpp(26): error C2065: 'SampleValue' : undeclared identifier
1>handmade.cpp(27): error C2065: 'SampleOut' : undeclared identifier
1>handmade.cpp(27): error C2065: 'SampleValue' : undeclared identifier
1>handmade.cpp(29): error C2065: 'tSine' : undeclared identifier
1>handmade.cpp(29): error C2065: 'Pi32' : undeclared identifier
1>handmade.cpp(29): error C2065: 'real32' : undeclared identifier
1>handmade.cpp(29): error C2146: syntax error : missing ';' before identifier 'WavePeriod'
1>handmade.cpp(34): error C2144: syntax error : 'void' should be preceded by ';'
1>handmade.cpp(34): error C4430: missing type specifier - int assumed. Note: C++ does not support default-int
1>handmade.cpp(34): error C2086: 'int internal' : redefinition
1>          \handmade.h(38) : see declaration of 'internal'
1>handmade.cpp(38): error C2065: 'uint8' : undeclared identifier
1>handmade.cpp(38): error C2065: 'Row' : undeclared identifier
1>handmade.cpp(38): error C2059: syntax error : ')'
1>handmade.cpp(43): error C2065: 'uint32' : undeclared identifier
1>handmade.cpp(43): error C2065: 'Pixel' : undeclared identifier
1>handmade.cpp(43): error C2059: syntax error : ')'
1>handmade.cpp(48): error C2065: 'uint8' : undeclared identifier
1>handmade.cpp(48): error C2146: syntax error : missing ';' before identifier 'Blue'
1>handmade.cpp(48): error C2065: 'Blue' : undeclared identifier
1>handmade.cpp(49): error C2065: 'uint8' : undeclared identifier
1>handmade.cpp(49): error C2146: syntax error : missing ';' before identifier 'Green'
1>handmade.cpp(49): error C2065: 'Green' : undeclared identifier
1>handmade.cpp(51): error C2065: 'Pixel' : undeclared identifier
1>handmade.cpp(51): error C2065: 'Green' : undeclared identifier
1>handmade.cpp(51): error C2065: 'Blue' : undeclared identifier
1>handmade.cpp(54): error C2065: 'Row' : undeclared identifier
1>handmade.cpp(59): error C2144: syntax error : 'void' should be preceded by ';'
1>handmade.cpp(59): error C4430: missing type specifier - int assumed. Note: C++ does not support default-int
1>handmade.cpp(59): error C2086: 'int internal' : redefinition
1>          \handmade.h(38) : see declaration of 'internal'
1>  Generating Code...
========== Build: 0 succeeded, 1 failed, 0 up-to-date, 0 skipped ==========
Mārtiņš Možeiko
2562 posts / 2 projects
Confusion when typedefing ints and uints ect
Have you added handmade.cpp file to Visual Studio project? If so, then that is a problem here. Because VS will try to compile handmade.cpp file independently which is not what you want. Because it is compiled as part of win32_handmade.cpp.

Either remove file from project, or exclude it from build so it is not compiled (press right mouse button on file, choose Properties, then select "No" for "Excluded From Build" setting).
Jordan Trainor
2 posts
Confusion when typedefing ints and uints ect
Thanks, changing the "Excluded From Build" setting got rid of all the errors and allowed me to compile.