I can't compile parts of the SDL 1.2 (here [1]) with the Visual C++ compiler. In particular, this part (lines 3, 16):
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17
// Inside BinaryFile.cpp
1 Uint64 InputBinaryFile::read(std::size_t n)
2 {
3 Uint64 value = 0; // No suitable constructor exists to convert from 'int' to 'Uint64'
4 std::size_t shift = 0;
5 do
6 {
7 if (bufferSize == 0)
8 {
9 if (!in.read(reinterpret_cast<char*>(&bufferData), 1))
10 {
11 bufferData = 0;
12 }
13 bufferSize = 8;
14 }
15 std::size_t rbits = std::min(bufferSize, n);
16 value |= (bufferData & ~(~Uint64(0) << rbits)) << shift; // Cannot cast from 'int' to 'Uint64' via functional-style cast
The compiler error:
1>...\C++\Projects\Brumbrumrally\src\BinaryFile.cpp(48,18): error C2440: 'initializing': cannot convert from 'int' to 'Uint64'
1>...\Code\C++\Projects\Brumbrumrally\src\BinaryFile.cpp(48,18): message : No constructor could take the source type, or constructor overload resolution was ambiguous
Uint64 isn't a language type. It's defined in \SDL-1.2\include\SDL_stdinc.h
1 2 3 4 5 6 7 8 9 10 11
#ifdef SDL_HAS_64BIT_TYPE
typedef int64_t Sint64;
#ifndef SYMBIAN32_GCCE
typedef uint64_t Uint64;
#endif
#else
/* This is really just a hack to prevent the compiler from complaining */
typedefstruct {
Uint32 hi;
Uint32 lo;
} Uint64, Sint64;
Any suggestions for fixing this?
I thought to specify a constructor for conversion from int but it's an anonymous class and that didn't work.
That would have the same problem, since it's just a typedef, no? (Very strong chance I'm wrong; I'm surprised this is even an issue in the first place). If just using std::uint64_t is the solution, why is the compiler being stricter for a typedef?
The error message seems to indicate the compiler thinks Uint64 is a class type, which means you probably configured the library incorrectly before trying to build it.
SDL 1.2 or SDL 2.0 is available as a package that vcpkg can integrate into Visual Studio. https://vcpkg.io/en/index.html
@ElusiveTau, you don't mention what version of MSVC++ you are using, vcpkg is supported for Visual Studio 2015 update 3 or higher. I know it works well with VS 2019 and VS 2022.
The tool downloads the chosen package, compiles it and sets all the needed paths so you don't have to do all the make work.
The error messages indeed suggest that Uint64 is being defined as a struct which means SDL_HAS_64BIT_TYPE has not been defined for some reason.
The comment says the struct is "just a hack to prevent the compiler from complaining" so I don't think it's actually meant to be used. It's not going to work as a fallback replacement for a 64-bit integer type.
I guess you could make the effort and write code that handles Uint64 being a struct but the project "Brum Brum Rally" that you're trying to build certainly doesn't (I know because I am the author).
You do have support for 64-bit integers on your computer, I'm almost certain, so the question is why SDL_HAS_64BIT_TYPE has not been defined.