Is the following code 100% portable?
int a=10; size_t size_of_int = (char *)(&a+1)-(char*)(&a); // No problem here? std::cout<
Yes, it gives you the equivalent of sizeof(a) but using ptrdiff_t instead of size_t type.
sizeof(a)
ptrdiff_t
size_t