在AIX中具有不同签名的结构之间的C ++类型转换

时间:2016-03-28 19:52:37

标签: c++ casting aix reinterpret-cast

我有两种结构:

typedef struct Struct1_t
{
  int a;
  uint b;
  int c;
}Struct1;

typedef struct Struct2_t
{
  uint x;
  uint y;
  int c;
}Struct2;

typedef Struct1 s1;
typedef Struct2 s2;

在函数中,我按以下方式使用类型转换:

s2 func(Struct1 s1, uint id) {
return reinterpret_cast<s2> ((static_cast<uint> (reinterpret_cast<uintprt_t> (s1))) + id);
}

这在Linux和Windows 64位环境中编译良好。但是在AIX中它仍然显示一条警告消息:

  

指针类型“s2 *”和类型“unsigned long”在当前别名模式下不兼容

我知道我在两种不兼容的类型之间进行投射,甚至尝试了一些解决方法,例如:

s1* s1_p = &s1;
s2* s2_p = reinterpret_cast<s2*> (s1_p);
return *s2;

但无济于事。

0 个答案:

没有答案