mmp / pbrt-v2

Source code for the version of pbrt described in the second edition of "Physically Based Rendering"
http://pbrt.org
990 stars 343 forks source link

Problems in Visual Studio and StdInt.h #17

Closed tonka3000 closed 10 years ago

tonka3000 commented 10 years ago

Hy,

i have a problem compiling pbrt-v2 correct if stdint.h is include. I've use Visual Studio 2010. The problem is when pbrt.h and stdint.h are both included (I use OpenCascade 6.7.0 to generate the meshes for pbrt). The problem is the pbrt-typedef of int8_t (i pbrt.h). VC++ 2010 does define int8_t with "signed char" => so typdef does see an error because the 2 definitions of int8_t are not the same.

pbrt.h (at the moment) ... typedef int8 int8_t; typedef unsigned __int8 uint8_t; typedef int16 int16_t; typedef unsigned int16 uint16_t; typedef __int32 int32_t; typedef unsigned int32 uint32_t; typedef __int64 int64_t; typedef unsigned __int64 uint64_t; ...

The problem is the "signed" modifier. typedef does work perfect if the int8_t is define as "signed __int8". The hole pbrt code works perfect with this change - so there should be no problem with that (with VC++). I have found a little project which tried to build a StdInt.h for Visual Studio C++ compiler (http://msinttypes.googlecode.com/svn/trunk/stdint.h). Their solution:

// Visual Studio 6 and Embedded Visual C++ 4 doesn't // realize that, e.g. char has the same size as int8 // so we give up on intX for them.

if (_MSC_VER < 1300)

typedef signed char int8_t; typedef signed short int16_t; typedef signed int int32_t; typedef unsigned char uint8_t; typedef unsigned short uint16_t; typedef unsigned int uint32_t;

else

typedef signed int8 int8_t; typedef signed __int16 int16_t; typedef signed int32 int32_t; typedef unsigned int8 uint8_t; typedef unsigned __int16 uint16_t; typedef unsigned int32 uint32_t;

endif

typedef signed __int64 int64_t; typedef unsigned __int64 uint64_t;

If I replace the old definition with the new one, pbrt-v2 will work absolutely perfect regardless of whether stdint.h is included or not. This should work with all VC++ compilers.

How to reproduce the problem: Add "#include " before "typedef __int8 int8_t;" in pbrt.h and try to compile with Visual Studio 2010.

Should I make a pull-request?

Greetings, Tonka

mmp commented 10 years ago

Sorry for the delay. Thanks for reporting this--fixed now!