Domanda

I would like to be able to write int32 instead of int and uint64 instead of unsigned __int64. I can accomplish this using typedefs by creating a file named PrimitiveTypes.h.

typedef signed char int8;
typedef signed short int16;
typedef signed int int32;
typedef unsigned char uint8;
typedef unsigned short uint16;
typedef unsigned int uint32;
typedef unsigned int uint;
typedef __int64 int64;
typedef unsigned __int64 uint64;

Now I can include PrimitiveTypes.h in every file that needs to use primitives, which turns out to be very close to every single file.

Perhaps this is bad practice, but is there a way add the re-definitions globally so I don't have to manually include the new primitives in every single file, or perhaps another solution to the problem? I'm using Visual Studio, in case there is any specific solutions.

È stato utile?

Soluzione 2

There's a /FI switch which Force Includes a header before the first line of code.

But ordinarily you'd just put it in the precompiled header. You mention in the comments that a big precompiled header is a bad idea. It's in fact the other way around. A large set of non-precompiled headers is a bad idea. You want as much precompiled as possible, even though most files won't need the full set.

Altri suggerimenti

In standard c++ we have the <cstdint> header for this.
Just say

#include <cstdint>

For older standards you can usually rely on

#include <stdint.h>

And yes you will have to include it at every file where you use these types. You may have a project central header file though, that is included everywhere anyway.

Autorizzato sotto: CC-BY-SA insieme a attribuzione
Non affiliato a StackOverflow
scroll top