In: Computer Science
Explain the concept of "range safe" in C++.
1- The C++ standard doesn't "reserve" any pointer addresses other than zero (null). So it is not safe to use 1 or any other value as a "magic" pointer value. Of course, in practice, some implementations of c++ probably do not every use certain values. But you don't get any guarantees from the language definition.
2- In C you can assume that NULL == 0
, only in C
NULL is a macro that defines NULL as an int that is equal to 0, C++
you do not have this liberty,
there are types, labels and values ( in better terms,
representations of values not real values ) for every variables, at
least for primitives values, the same is for the pointers, if you
are speaking about void pointers you are speaking about pointers
that contains a memory address ( just like any pointer ) and the
only special thing about this pointers is that they need a cast in
C++ to be decoded, safely and effectively; it's a big mistake if
you think about void*
as pointers that points to
nowhere or to 0
or to NULL
or to
0x0000000
3- The ranges library in C++20, working with the Standard Template Library (STL) will become much more comfortable and powerful. The algorithms of the ranges library are lazy, can work directly on the container and can easily be composed. To make it short: The comfort and the power of the ranges library are due to its functional ideas,