It seems on XCode I need to use std::size_t instead of just size_t on Visual C++. But this is a pain as I don’t really want to have to #include <cstddef> and change every size_t to std::size_t in my code… in my Windows code size_t just works without including any additional files.
Is there a way to make my existing code work in XCode, (maybe through the .pch file?) or are GCC/MSVC++ fundamentally different in this regard and my code needs to use std::size_t in order to be cross-platform?
According to the C++03 standard, 17.4.1.2.4:
In other words, by choosing to use
<cstddef>instead of<stddef.h>, you’re specifically asking for the type size_t to be within the namespace std.So, here are the choices:
Use
<stddef.h>instead, sosize_tis in the top-level namespace, as suggested by Jesse Good.Use
<cstddef>and usestd::size_t.Use
<cstddef>and use a using declaration to pullsize_tinto the top-level namespace, as suggested by cnicutar.Of course you could rely on the fact that one particular version of one compiler/library/platform lets you get away with it, or write different code for each platform, or wrap the whole thing up with autoconf, or write a code generator or sed-based preprocessor, or whatever… but why?