Search code examples
c++cintcompiler-options

C/C++ Compiler that allows int width selection


Does anyone know of a modern native Windows C or C++ compiler that allows you to select between 16-bit and 32-bit type int? I encountered a cross-compiler back in the 80s that had this feature but I need a native compiler. As part of teaching my students about portability and standards compliance I would like to be able to automatically check their code for overflow if they are multiplying, adding, etc. two type int quantities and the result would be greater than a 16-bit int could represent. Thanks.


Solution

  • See the integer types defined in C++11 and forth: http://en.cppreference.com/w/cpp/types/integer : int8_t, int16_t, int32_t, int64_t

    These should be supported by almost any modern C++ compiler: GCC you can use MinGW on Windows, MSVC, Intel, Clang, even Borland/Codegear/Embarcardero as they are now part of the standard.

    The fixed width integral types has been part of the C language since C99, but was finally added to C++ in C++11 see: N1988