DEV Community

Discussion on: Datatype size in C++

Collapse
 
pgradot profile image
Pierre Gradot • Edited

Hello,

I think you are missing 3 points here.

First, C++ offers an awesome template class to get the maximum value that a type can held: std::numeric_limits. Example:

#include <limits>

 std::cout << std::numeric_limits<unsigned char>::max() << '\n';

Second, there is a area where we do care about memory footprint: embedded systems == IoT. Furthermore, this is an area where C and C++ are by far the most used languages.

Last, and by far the most important: the results of your code in the article depend on the compiler and target CPU. This is a critical point in C and C++. See for instance the section Data models and the first chart on this page. The outputs you get are typical on a computer nowadays. But on embedded systems you will get different results.

It is important to tell people that types have a memory footprint. But it is more important to tell them that it is also complicated.