Day 16 - Just so many errors

I have been working through the days, and mostly everything has been working, but my code is 'a little' different here and there. However, tonight something just wouldn't work and so I changed some stuff around, and now I have anywhere between 100 and 300 errors. Many of which are completely stupid, such as telling me that Data is not a member of SoundBuffer, when it is.

Trying to hone in on the real problems I see some issues with the code that I had managed to work around, until tonight. So one issue is ...

* In handmade.cpp - sinf() is used, while math.h isn't included in that file, nor in the header file. So the identifier is undefined. I think this was one of the early differences in my code and Casey's. I never understood how his code compiled.

* The same with all the int defines (real32 etc), they are undefined.

If I can fix these two issues, I can move forward perhaps to the other 143 errors now.
win32_handmade.cpp includes math.h, typedef the "custom" types and then includes handmade.h and handmade.cpp. All those files are compiled in the same compile unit so you can use sinf and real32 types.

The includes and type definitions have been changed at some point to be better organized.
So maybe on my computer they aren't in the same compile unit. I'm sure I've missed something. I'm using Visual Studio to build and run.
Just start with first error. Don't look at big error list from bottom or middle.

Typically by fixing few first errors all of them will be fixed and will go away. This is because when compiler is parsing source code, and it is missing some type or variable definition, then the errors below simply are consequences of that. When first error will be fixed, most of them about missing type/declaration/whatever will go away.
Ok, so the first error is

Error 1 error C2146: syntax error : missing ';' before identifier 'SafeTruncateUInt64' (Handmade.cpp) e:\handmadehero\handmade.h 43 1 HandmadeHero

Here is the code :

 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
13
14
15
16
17
18
19
20
#if !defined(HANDMADE_H)

#if SLOW
	#define Assert(Expression) if (!(Expression)) { *(int*)0 = 0; }
#else
	#define Assert(Expression)
#endif
#define ArrayCount(Array) (sizeof(Array) / sizeof((Array)[0]))
#define Kilobytes(Value) ((Value)*1024)
#define Megabytes(Value) (Kilobytes(Value)*1024)
#define Gigabytes(Value) (Megabytes(Value)*1024)
#define Terabytes(Value) (Gigabytes(Value)*1024)

inline uint32
// Debug function
SafeTruncateUInt64(uint64 v)
{
	Assert(v <= 0xFFFFFFFF);
	return (uint32)v;
}


I don't find that error particularly helpful.

Edit (more info) : Following errors include:

error C2433: 'uint32' : 'inline' not permitted on data declarations
error C4430: missing type specifier - int assumed. Note: C++ does not support default-int
error C2065: 'uint64' : undeclared identifier
error C2146: syntax error : missing ')' before identifier 'v'

These are all ridiculous error message!

Edited by Gavin Williams on
Are you using a single translation unit? Maybe some of your includes are not in proper order?
This error means that "uint32_t" is unknown to compiler. Have you included <stdint.h> somewhere above in this file?
I guess you still haven't typedef'd uint32, uint64, etc. The compiler is looking at uint32 above SafeTruncateUInt64 and thinks you are trying to declare a variable since it knows it's not a type. A variable declaration would require a semicolon afterwards, hence your first error. The rest follow from that.
Bah, I can't read :) stdint.h with uint32_t is not the problem! oliholli explained correctly what is problem - uint32 type. Check if that is typedef'd somwhere above.
I have the typedef's in Win32Handmade.cpp. I just notices a VS2013 settings file in the hh source, I'm going to try to apply that.

Edited by Gavin Williams on
But is Win32Handmade.cpp included in this file you are showing? Or is this file included in Win32Handmade.cpp below where uint32 is?

You understand how #includes work? Preprocessor simply copy&pastes code from files where they are #include'd, so at then end there is only one file to compile without any #includes, and if order of declarations is wrong there, you'll get errors.
 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
/* ================================================================================================
	Project : HandmadeHero
	Author : 
	Date : 2015.01.15 
   ================================================================================================ */

#pragma comment(lib, "dsound.lib") // alternative to adding the lib as an additional dependancy
//#pragma comment(lib, "dxguid.lib")
//#pragma comment(lib, "winmm.lib")
#include <math.h>
#include <stdint.h> // provides int types

#define internal static

#define Pi32 = 3.14159265359f;

typedef int8_t int8;
typedef int16_t int16;
typedef int32_t int32;
typedef int64_t int64;

typedef uint8_t uint8;
typedef uint16_t uint16;
typedef uint32_t uint32;
typedef uint64_t uint64;

typedef float real32;
typedef double real64;
typedef int8_t int8;
typedef int bool32;

#include <dsound.h>
#include <malloc.h>
#include <Windows.h>
#include <Xinput.h>
#include "Win32Handmade.h"
#include "Handmade.cpp"
When you get errors, which file are you compiling? Win32Handmade.cpp?
I don't use VisualStudio but it is fairly typical that .cpp files will be compiled separately and linked by default. This goes against the unity build which has one .cpp file #include all the others which means you may have to fight VisualStudio to stop compiling the other .cpp files.
Ok, thanks guys for helping out, I think I AM fighting VS :( That sounds like what's happening, because there is no way to turn off compilation for a files without removing them from the project, but I will try.