我正在http://sourceforge.net/projects/dtmf/上学习DTMF代码.我遇到了一些我无法理解的C++代码:
template<int, int, int, int> class Types;
template <> class Types<5, 4, 2, 1>
{
public:
typedef long int Int40;
typedef unsigned long int Uint40;
typedef int Int32;
typedef unsigned int Uint32;
typedef short int Int16;
typedef unsigned short int Uint16;
typedef char Int8;
typedef unsigned char Uint8;
};
template <> class Types<8, 4, 2, 1>
{
public:
typedef long int Int64;
typedef unsigned long int Uint64;
typedef int Int32;
typedef unsigned int Uint32;
typedef short int Int16;
typedef unsigned short int Uint16;
typedef char Int8;
typedef unsigned char Uint8;
};
template <> class Types<4, 4, 2, 1>
{
public:
typedef int Int32;
typedef unsigned int Uint32;
typedef short int Int16;
typedef unsigned short int Uint16;
typedef char Int8;
typedef unsigned char Uint8;
};
// For 16bit chars
template <> class Types<2, 1, 1, 1>
{
public:
typedef long int Int32;
typedef unsigned long int Uint32;
typedef short int Int16;
typedef unsigned short int Uint16;
};
typedef Types<sizeof(long int), sizeof(int), sizeof(short int), sizeof(char)>::Int32 INT32;
typedef Types<sizeof(long int), sizeof(int), sizeof(short int), sizeof(char)>::Uint32 UINT32;
typedef Types<sizeof(long int), sizeof(int), sizeof(short int), sizeof(char)>::Int16 INT16;
typedef Types<sizeof(long int), sizeof(int), sizeof(short int), sizeof(char)>::Uint16 UINT16;
Run Code Online (Sandbox Code Playgroud)
从那里,它们就像普通的原始类型一样使用:
static const INT16 tempCoeff[8];
Run Code Online (Sandbox Code Playgroud)
我的直觉告诉我,所有这些东西都实现了某种跨平台的可移植性.我是对的,还是有更多的东西?
看起来他们正在重新发明stdint.h(我相信在某些/许多版本的MS编译器中不支持),它通过为基于调用的某些大小的整数类型提供一些可移植的机制sizeof.请注意,接受的第四个模板参数sizeof(char)完全没用,因为sizeof(char)始终为1.
| 归档时间: |
|
| 查看次数: |
316 次 |
| 最近记录: |