Which C ++ compilers automatically detect size_t without including a header?

When using the Visual Studio 2013 C ++ compiler, I noticed that my code based on size_t was compiled correctly even without including the headers that defined it (i.e. #include <stddef.h>or #include <string.h>).

I tested this because I kind of got the idea of ​​not including the whole title just for something trivial; I feel like this is inflating my code. I came to the conclusion that the C ++ Visual Studio 2013 compiler automatically detects size_t, even without any header inclusions in the code.

While I enjoyed it, I began to worry about portability. Convenience coding and the feeling that my code is elegant is more important to me than absolute mobility; but I would still like mobility. For example, I do not mind using it #pragma once, since most compilers support it, and protecting headers is a problem (especially in Visual Studio), but I would never resort to exporting templates just because one compiler supports it.

So my question is, is automatic size_t detection a widespread feature offered by many compilers, or is it something specific to the Microsoft compiler?

+4
source share
2 answers

Such behavior, of course, is not widespread; both GCC and Clang require inclusion <cstddef>for std::size_tor deprecated <stddef.h>for ::size_t, as the standard indicates.

+10
source

Neither gcc nor clang contain a similar violation of the C ++ standard .

Between 3, MSVC gcc and clang make up the vast majority of compilers.

The same goes for icc 13.0.1 .

I have not tried ECG , feel free.

+4
source

All Articles