![| Learn C++ What Are Function Macros For Integer Constants](https://i0.wp.com/learncplusplus.org/wp-content/uploads/2023/04/pexels-kamaji-ogino-5093642-scaled.jpg?resize=1140%2C694&ssl=1)
![| Learn C++ What Are Function Macros For Integer Constants](https://i0.wp.com/learncplusplus.org/wp-content/uploads/2023/04/pexels-kamaji-ogino-5093642-scaled.jpg?resize=1140%2C694&ssl=1)
In C++ coding, there are function macros for the fixed-width integer type that expands to an integer constant expression having the value specified by its argument. Their type is the promoted type of std::int_least8_t
, std::int_least16_t
, std::int_least32_t
, and std::int_least64_t
and unsigned versions of these types respectively. In this post, we explain these function macros for integer constants in Modern C++.
Table of Contents
What are function macros for signed integer constants?
Here are the function macros for the fixed-width integer type that expands to an integer constant expression having the value specified by its argument. Their type is the promoted type of std::int_least8_t
, std::int_least16_t
, std::int_least32_t
and std::int_least64_t
respectively,
Fixed Width Integer Types | Description |
INT8_C | expands to an integer constant whose type is std::int_least8_t |
INT16_C | expands to an integer constant whose type is std::int_least16_t |
INT32_C | expands to an integer constant whose type is std::int_least32_t |
INT64_C | expands to an integer constant whose type is std::int_least64_t |
What are function macros for unsigned integer constants?
Here are the function macros for the fixed-width integer type that expands to an integer constant expression having the value specified by its argument. Their type is the promoted type of std::uint_least8_t
, std::uint_least16_t
, std::uint_least32_t
and std::uint_least64_t
respectively.
Fixed Width Integer Types | Description |
UINT8_C | expands to an unsigned integer constant whose type is std::uint_least8_t |
UINT16_C | expands to an unsigned integer constant whose type is std::uint_least16_t |
UINT32_C | expands to an unsigned integer constant whose type is std::uint_least32_t |
UINT64_C | expands to an unsigned integer constant whose type is std::uint_least64_t |
What are other function macros for integer constants?
INTMAX_C
function macro, expands to an integer constant whose type is std::intmax_t
,
Fixed Width Integer Types | Description |
INTMAX_C | min. value of 8 bits signed integer type |
UINTMAX_C
function macro, expands to an integer constant whose type is std::ıintmax_t
,
Fixed Width Integer Types | Description |
UINTMAX_C | min. value of 8 bits signed integer type |
If you are looking more about Integer Constants there are more details about them, https://docwiki.embarcadero.com/RADStudio/Alexandria/en/Integer_Constants
If you are looking more about Declared Constants, you can follow this link: https://docwiki.embarcadero.com/RADStudio/Alexandria/en/Declared_Constants
Is there a simple C++ example of using function macros for integer constants?
Here is a very simple C++ example of how you can use function macros for integer constants.
1 2 3 4 |
std::cout << INT8_C(-128) << std::endl; std::cout << UINT8_C(255) << std::endl; |
Is there a full C++ example of how to use function macros for integer constants?
Here is a full C++ example of how to use function macros for integer constants.
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 |
#include <iostream> #include <tchar.h> int _tmain(int argc, _TCHAR* argv[]) { std::cout << INT8_C(-128) << std::endl; std::cout << UINT8_C(255) << std::endl; std::wcout << (wchar_t)INT16_C(-32767) << std::endl; std::wcout << (wchar_t)UINT16_C(655385) << std::endl; system("pause"); return 0; } |
![CBuilder11512x5121x | Learn C++ What Are Function Macros For Integer Constants The C++ Builder Logo](https://i0.wp.com/learncplusplus.org/wp-content/uploads/2021/09/CBuilder_11_512x512@1x.png?resize=128%2C128)
![CBuilder11512x5121x | Learn C++ What Are Function Macros For Integer Constants The C++ Builder Logo](https://i0.wp.com/learncplusplus.org/wp-content/uploads/2021/09/CBuilder_11_512x512@1x.png?resize=128%2C128)
C++ Builder is the easiest and fastest C and C++ IDE for building simple or professional applications on the Windows, MacOS, iOS & Android operating systems. It is also easy for beginners to learn with its wide range of samples, tutorials, help files, and LSP support for code. RAD Studio’s C++ Builder version comes with the award-winning VCL framework for high-performance native Windows apps and the powerful FireMonkey (FMX) framework for cross-platform UIs.