Partager via


VC's "evil" extension: Pre-definition of basic types

In VC, you may find that you can use "size_t" directly without including any headers.

size_t i = 0;

int main()
{
    atexit(0);
}

However, "size_t" is not a built-in type. It is a typedef in <stddef.h>. So what's the magic?

In VC compiler, it will include some internal headers for various reasons before compile your code.

For example, "size_t" and "atexit" are introduced in the internal header to support EH (Exception Handling) and RTTI (Run-Time Type Information).

It's better not to rely on this extension. Whenever you use the types / functions, include the corresponding headers. Otherwise your code will break on other compilers :-)