For fun, here's an example where you can generate long pointer types using templates. The compiler will generate types with hundreds of levels of indirection.
#include <iostream>
template<size_t N, typename T>
struct PointerVariable
{
T* myPtr;
PointerVariable<N - 1, T*> ptrToMyPtr;
PointerVariable(T* p) :
myPtr(p),
ptrToMyPtr(&myPtr)
{
// display pointer value
std::cout << "ptr:" << ((void*)myPtr) << std::endl;
}
};
template<typename T>
struct PointerVariable<0, T>
{
PointerVariable(T* p) {
int a = 3.3; // generate a compiler warning so we can see the names of types
}
};
int main()
{
int val = 0;
auto pp = PointerVariable<499, int>{ &val };
return 0;
}
On MSVC++2019, this produces a compiler warning:
warning C4244: 'initializing': conversion from 'double' to 'int', possible loss of data
message : while compiling class template member function 'PointerVariable<0,T *>::PointerVariable(int ********************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************)'
And when N=500, a compiler error occurs:
fatal error C1202: recursive type or function dependency context too complex
Using an explicit type, VC++2019 allows 1491 levels of indirection:
int
******************************************************************************************************************************** // 128
******************************************************************************************************************************** // 128
******************************************************************************************************************************** // 128
******************************************************************************************************************************** // 128
******************************************************************************************************************************** // 128
******************************************************************************************************************************** // 128
******************************************************************************************************************************** // 128
******************************************************************************************************************************** // 128
******************************************************************************************************************************** // 128
******************************************************************************************************************************** // 128
******************************************************************************************************************************** // 128
**************************************************************** // 64
**************** // 16
*** // 3
x = nullptr;
Adding one more pointer level emits:
fatal error C1026: parser stack overflow, program too complex
This is an exercise of the compiler's abilities regarding variable storage and type complexity. Ignoring these 2 limitations, for example by just working with uintptr_t
instead of real pointer types, then your limitation is system memory.