Handmade Hero»Forums»Code
Leonid Kapitonov
8 posts
Game developer, C, C++, Unity
Warnings as errors flag
Casey, since you are using -WX flag (Treat Linker Warnings as Errors), it's impossible to compile the project with it. That is not a problem, one can simply remove the flag or fix the issues, but I can't see you getting the same warnings at all.

I have used Visual Studio Community, if that matters.

1
2
3
4
5
6
7
8
9
handmade.cpp
   Creating library handmade.lib and object handmade.exp
win32_handmade.cpp
g:\fantasy\projects\handmade hero\handmade\code\win32_handmade.cpp(78) : error C2220: warning treated as error - no 'object' file generated
g:\fantasy\projects\handmade hero\handmade\code\win32_handmade.cpp(78) : warning C4018: '<' : signed/unsigned mismatch
g:\fantasy\projects\handmade hero\handmade\code\win32_handmade.cpp(85) : warning C4018: '<' : signed/unsigned mismatch
g:\fantasy\projects\handmade hero\handmade\code\win32_handmade.cpp(677) : warning C4244: 'argument' : conversion from 'uint64' to 'size_t', possible loss of data
g:\fantasy\projects\handmade hero\handmade\code\win32_handmade.cpp(706) : warning C4244: 'argument' : conversion from 'uint64' to 'size_t', possible loss of data
g:\fantasy\projects\handmade hero\handmade\code\win32_handmade.cpp(1138) : warning C4244: 'argument' : conversion from 'uint64' to 'SIZE_T', possible loss of data


And thank you for the Handmade Hero! Cheers!
Warnings as errors flag
Edited by Class GenericHuman on
Are those linker warnings or compiler warnings?
C2220 - http://msdn.microsoft.com/en-us/library/ksk5k0ta.aspx
C4018 - http://msdn.microsoft.com/en-us/library/y92ktdf2.aspx
C4244 - http://msdn.microsoft.com/en-us/library/th7a07tz.aspx

All of these are compiler errors.

Edit:- But then again WX is for compiler and not linker so it is the reason you are getting these warnings as errors. What day's code are you using?
Leonid Kapitonov
8 posts
Game developer, C, C++, Unity
Warnings as errors flag
The flag is for the compiler. I just made a typo with the flag name: copypasted from google. I am sorry for the misguide :)

Anyway, the day is 31, and what I am saying, this compiler flag is among Casey's:
1
set CommonCompilerFlags=-MTd -nologo -Gm- -GR- -EHa- -Od -Oi [b]-WX[/b] -W4 ... etc


But he does not get any warnings, so I want it to be cleared and brought to the surface.

==== ==== ==== ==== ==== ==== ==== ====

As a matter of fact, I modify his build batch files:

"setup.bat"
1
2
@echo off
call "C:\Program Files (x86)\Microsoft Visual Studio 12.0\VC\vcvarsall.bat"


"build.bat"
 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
13
14
15
16
17
@echo off

set cl_path=C:\Program Files (x86)\Microsoft Visual Studio 12.0\VC\bin

set CommonCompilerFlags=-MTd -nologo -Gm- -GR- -EHa- -Od -Oi -WX -W4 -wd4201 -wd4100 -wd4189 -wd4505 -DHANDMADE_INTERNAL=1 -DHANDMADE_SLOW=1 -DHANDMADE_WIN32=1 -FC -Z7
set CommonLinkerFlags= -incremental:no -opt:ref user32.lib gdi32.lib winmm.lib

REM TODO - can we just build both with one exe?

REM 32-bit build
REM "%cl_path%\cl" %CommonCompilerFlags% ..\code\win32_handmade.cpp /link -subsystem:windows,5.1 %CommonLinkerFlags%

REM 64-bit build
del *.pdb > NUL 2> NUL
REM Optimization switches /O2 /Oi /fp:fast
"%cl_path%\cl" %CommonCompilerFlags% ..\code\handmade.cpp -Fmhandmade.map -LD /link -incremental:no -opt:ref -PDB:handmade_%random%.pdb -EXPORT:GameGetSoundSamples -EXPORT:GameUpdateAndRender
"%cl_path%\cl" %CommonCompilerFlags% ..\code\win32_handmade.cpp -Fmwin32_handmade.map /link %CommonLinkerFlags%


usage is simple:
  1. open command line
  2. setup once
  3. build when needed
Warnings as errors flag
In the shell.bat Casey provides, he runs vcvarsall.bat with the argument x64. This tells vcvarsall to do the setup for x64. You have not provided that.

Im assuming that because of the lack of x64 as the argument, vcvarsall has setup for ³²bit, which means Size_t will be 32 bit and hence not match with uint64 which is 64 bit.
Leonid Kapitonov
8 posts
Game developer, C, C++, Unity
Warnings as errors flag
I see, I see, thanks! I assume, signed/unsigned mismatch comes from there equally.
Still, when one builds for x32, this little underdone things should be fixed. Two interacting variables should be of the same type. By declaration or by conversion.
Warnings as errors flag
Not really. size_t is unsigned for both x86 and x64. In the code on line 77 and 84 of win32_handmade.cpp, it should be uint32/uint64 Index and not int Index. int Index is signed and size of a buffer is never negative so using uint32/uint64 is more 'correct'.