Take the following standard passage:
[C++11: 5.3.3/6]:
The result ofsizeof
andsizeof...
is a constant of typestd::size_t
. [ Note:std::size_t
is defined in the standard header<cstddef>
(18.2). —end note ]
Now:
[C++11: 18.2/6]:
The typesize_t
is an implementation-defined unsigned integer type that is large enough to contain the size in bytes of any object.
Granted, the passage doesn't require that size_t
is a type alias defined with typedef
, but since it's explicitly stated to be made available by the standard header <cstddef>
, I think we can take as read that failing to include <cstddef>
should remove any guarantee that size_t
shall be available to a program.
However, according to that first quote, we can regardless obtain an expression of type std::size_t
.
We can actually demonstrate both of these facts:
int main()
{
typedef decltype(sizeof(0)) my_size_t;
my_size_t x = 0; // OK
std::size_t y = 1; // error: 'size_t' is not a member of 'std'
}
std::size_t
is not visible to the program, but sizeof(0)
still gives us one? Really?
Is it therefore not correct to say that 5.3.3/6
is flawed, and that it actually has "the same type as whatever std::size_t
resolves to", but not std::size_t
itself?
Sure, the two are one and the same if std::size_t
is a type alias but, again, nowhere is this actually required.
std::size_t
, regardless of howsize_t
is defined or whether it's an alias for anything. That said, I'm not enough of a C++ language lawyer to answer this question. – Fleurcstddef
to use thesize_t
name, but not thesize_t
type. – Fleurint
andlong
are distinct types, despite having the same properties on my platform. – Overdevelopoperator new
,operator delete
and variations thereof are also available without the inclusion of any header files, but somewhere in the standard (I suppose 3.7.4 but not sure), I read that using them "does not make the operatorstd::operator new(std::size_t)
visible", or something like that. – Demoralizey
to compile just becausex
did. – Overdevelopsizeof
and this name, which is wrong?! Of course I'm being massively picky... – Overdevelop