0

I used to write my code with JB Rider and compile it with VS native C++ compiler (CL). A few days ago I decided to use JB CLion with CMake. I thought that it should use my native compiler as well, so no differences should appear.

However

I have some code

uint64 size = get_some_size();
byte* buffer = new byte[size];

This code compiles without warnings in Rider, but when I run build with CMake I get:

warning C4244: 'initializing': conversion from 'uint64' to 'unsigned int', possible loss of data

It seems like CMake build force arrays to have size in unsigned int32. Why and how to fix that?

Espeon
  • 208
  • 1
  • 11
  • 5
    CMake doesn't build anything ... That's the compiler. Are you building in 32-bit by mistake? – ChrisMM Nov 17 '22 at 00:35
  • 4
    If you build for 32 bit subsystem of windows then of course array size is 32 bit. – Öö Tiib Nov 17 '22 at 00:35
  • @ChrisMM Probably, yes. How can I tell it to build exactly in 64-bit? – Espeon Nov 17 '22 at 00:39
  • Check the options of the compiler you are using, it should have a way to specify the target architecture. – Remy Lebeau Nov 17 '22 at 00:40
  • 2
    [How to build x86 and/or x64 on Windows from command line with CMAKE?](https://stackoverflow.com/questions/28350214/how-to-build-x86-and-or-x64-on-windows-from-command-line-with-cmake) - you can run it with `-A x64` – dewaffled Nov 17 '22 at 00:40
  • 2
    If using `GCC` or `CLANG` as the compiler, you can do `-m32` or `-m64` in the `target_compile_options` – Brandon Nov 17 '22 at 00:42
  • Thank you, it helped :) With CLion I had to open `File->Settings->...->Toolchains` and in "Visual Studio" toolchain set "Architecture" to "x64" (if unset, it use x86) – Espeon Nov 17 '22 at 00:50
  • Does this answer your question? [How to build x86 and/or x64 on Windows from command line with CMAKE?](https://stackoverflow.com/questions/28350214/how-to-build-x86-and-or-x64-on-windows-from-command-line-with-cmake) – starball Nov 17 '22 at 02:40
  • 2
    While I realise the question is about how to build in 64-bit rather than 32-bit, why are you using `uint64` instead of `size_t` to represent array sizes? – Peter Nov 17 '22 at 02:57
  • @starball later yes, but initial question was about why I'm getting warnings about `uint64` being an array size – Espeon Nov 17 '22 at 03:19
  • @Peter good comment, I'll probably change that later. I never compiled a code on 32-bit architecture so I didn't knew that it also affects an array size type, I knew only about pointer type – Espeon Nov 17 '22 at 03:20

0 Answers0