Predefined C++ Types

Every C and C++ source file compiled with Microsoft Visual C++ has, in effect, a forced inclusion of a header file written by Microsoft to provide some predefined types. These pre-definitions do not exist as a separate file but are hard-coded into the compiler (C1 or C1XX). They are reproduced here for the critical interest of programmers who may care to know what code has already been written for them. The extraction is complete and the lines are presented in the compiler’s order. However, a small amount of editing has been applied line by line for readability, since the compiler’s code tends not to bother with any sort of indenting or consistent use of white space.

Name

A file name of sorts is provided via a #line directive to the preprocessor:

#line 15 "predefined C++ types (compiler internal)"

The significance of starting the “file” at line 15, specifically, is not known. As an aside, note that although the name speaks of C++ specifically, it applies to both the C and C++ compilers.

Size Type

A type, size_t, is built into the language as the type returned by the sizeof operator and (in C++) as the type required for the first argument of operator new. However, the definition of this type is formally left to header files that are expected to be supplied with the C Run-Time Library (CRT). Microsoft Visual C++ helpfully defines size_t for those programmers who are not using any CRT headers.

The C++ compiler pre-defines size_t no matter what:

#if Wp64
typedef __w64 unsigned int size_t;
#else
typedef unsigned int size_t;
#endif

but the C compiler defines it only conditionally:

#if Wp64
typedef __w64 unsigned int size_t;
#endif

Note that the choice in C++ is governed by the macro Wp64 with no leading underscore, not by the macro _Wp64 that is defined by CL as an implication of the /Wp64 option.

New and Delete Operators (C++ Only)

C++ programmers never have to define global new and delete operators, either explicitly or by including a CRT header. The compiler has done it for them.

extern __declspec (unmanaged) void * __cdecl operator new (size_t);
extern __declspec (unmanaged) void __cdecl operator delete (void *);

Static Destructors (C++ Only)

extern "C" __declspec (unmanaged) int __cdecl atexit (void (__cdecl *) (void));

Exception Handling (C++ Only)

#pragma pack (push, ehdata, 4)

typedef struct _PMD
{
    int mdisp;
    int pdisp;
    int vdisp;
} _PMD;

typedef void (*_PMFN) (void);

#pragma warning (disable:4200)
#pragma pack (push, _TypeDescriptor, 8)
typedef struct _TypeDescriptor
{
    const void *pVFTable;
    void *spare;
    char name [];
} _TypeDescriptor;
#pragma pack (pop, _TypeDescriptor)
#pragma warning (default:4200)

typedef const struct _s__CatchableType {
    unsigned int properties;
    _TypeDescriptor *pType;
    _PMD thisDisplacement;
    int sizeOrOffset;
    _PMFN copyFunction;
} _CatchableType;

#pragma warning (disable:4200)
typedef const struct _s__CatchableTypeArray {
    int nCatchableTypes;
    _CatchableType *arrayOfCatchableTypes [];
} _CatchableTypeArray;
#pragma warning (default:4200)

typedef const struct _s__ThrowInfo {
    unsigned int attributes;
    _PMFN pmfnUnwind;
    int (__cdecl *pForwardCompat) (...);
    _CatchableTypeArray *pCatchableTypeArray;
} _ThrowInfo;

__declspec (noreturn) extern "C" void __stdcall _CxxThrowException (void *pExceptionObject, _ThrowInfo * pThrowInfo);
extern "C" int __cdecl __CxxExceptionFilter (void *, void *, int, void *);
extern "C" int __cdecl __CxxRegisterExceptionObject (void *exception, void *storage);
extern "C" int __cdecl __CxxDetectRethrow (void *exception);
extern "C" int __cdecl __CxxQueryExceptionSize (void);
extern "C" void __cdecl __CxxUnregisterExceptionObject (void *storage, int rethrow);

#pragma pack (pop, ehdata)

Run-Time Type Information (C++ Only)

#pragma pack (push, rttidata, 4)

typedef const struct _s__RTTIBaseClassDescriptor {
    _TypeDescriptor *pTypeDescriptor;
    unsigned long numContainedBases;
    _PMD where;
    unsigned long attributes;
} __RTTIBaseClassDescriptor;

#pragma warning (disable:4200)
typedef const struct _s__RTTIBaseClassArray {
    __RTTIBaseClassDescriptor *arrayOfBaseClassDescriptors [];
} __RTTIBaseClassArray;
#pragma warning (default:4200)

typedef const struct _s__RTTIClassHierarchyDescriptor {
    unsigned long signature;
    unsigned long attributes;
    unsigned long numBaseClasses;
    __RTTIBaseClassArray *pBaseClassArray;
} __RTTIClassHierarchyDescriptor;

typedef const struct _s__RTTICompleteObjectLocator {
    unsigned long signature;
    unsigned long offset;
    unsigned long cdOffset;
    _TypeDescriptor *pTypeDescriptor;
    __RTTIClassHierarchyDescriptor *pClassDescriptor;
} __RTTICompleteObjectLocator;

typedef const class type_info &__RTtypeidReturnType;

extern "C" void * __cdecl __RTDynamicCast (
    void *,
    long,
    void *,
    void *,
    int) throw (...);
extern "C" void * __cdecl __RTtypeid (void *) throw (...);
extern "C" void * __cdecl __RTCastToVoid (void *) throw (...);

#pragma pack (pop, rttidata)

GUID (C++ Only)

struct __s_GUID {
    unsigned long Data1;
    unsigned short Data2;
    unsigned short Data3;
    unsigned char Data4 [8];
};

typedef const struct _GUID &__rcGUID_t;

Intrinsics

Functions for which the compiler is to provide its own implementations ordinarily must be declared (with C linkage) before use. For who knows what reason, Microsoft makes exceptions for two of these intrinsics.

For __debugbreak, the C and C++ declarations differ only in that extern "C" is omitted for C.

extern "C"
__declspec (unmanaged) void __cdecl __debugbreak (void);

For __annotation, which Microsoft anyway does not document, the C compiler omits not just the extern "C" but also the alternative declaration in terms of the native wchar_t type.

extern "C"
#if defined(_NATIVE_WCHAR_T_DEFINED)
__declspec (unmanaged) void __cdecl __annotation (const wchar_t *, ...);
#else
__declspec (unmanaged) void __cdecl __annotation (const unsigned short *, ...);
#endif