在某个特定的情况下,你的代码中的 int8_t/int16_t/int32_t/int64_t/uint8_t/uint16_t/uint32_t/uint64_t 都会变成 32 位的。比如你定义了一个结构体 struct MessageHeader{ int64_t messageId; int32_t messageType; };
结果,在同一个程序中,它一会儿是 12 个字节,一会儿是 8 字节。这样的奇妙问题足够让你 debug 很久……
问题出在 glibc 的 argp 这个烂玩意儿上: https://bugzilla.redhat.com/show_bug.cgi?id=1366830
|      1hitmanx      2016-08-13 18:21:55 +08:00 #ifndef __attribute__ /* This feature is available in gcc versions 2.5 and later. */ # if __GNUC__ < 2 || (__GNUC__ == 2 && __GNUC_MINOR__ < 5) || \ defined __STRICT_ANSI__ # define __attribute__(Spec) /* empty */ # endif ... 能解释一下嘛,为什么(__GNUC__ < 2 || (__GNUC__ == 2 && __GNUC_MINOR__ < 5))能成立?你的 gcc 版本比它要高啊。还有为啥__attribute__会没有定义过(#ifndef __attribute__)? | 
|  |      4est      2016-08-13 19:33:31 +08:00  3 V 站最近看到最有技术含量的一个帖子。 | 
|  |      6forcecharlie      2016-08-13 19:39:59 +08:00 换行稍微不注意就有 bug 了 | 
|  |      8skydiver      2016-08-13 19:53:12 +08:00 via iPad 这几个类型在 cstdlib 里面,可是你并没有 include | 
|  |      9vietor      2016-08-13 19:55:34 +08:00 via Android 你没定义对齐 | 
|  |      13skydiver      2016-08-13 21:22:16 +08:00 在 Fedora24 里试验了,也可以重现这个 bug | 
|  |      15skydiver      2016-08-13 21:26:54 +08:00 可以先 workaround 一下把 #include<stdint.h> 放到最前面结果就对了…… | 
|  |      17lizhenda      2016-08-14 14:19:08 +08:00 这个厉害啊 | 
|      19onlyhuochetou      2016-08-15 17:58:45 +08:00 确实是一个问题。 可是为什么不将 argp.h 写在 stdio.h 后面呢? | 
|  |      20skydiver      2016-08-20 23:36:57 +08:00 glibc-2.23.1-10 里面已经修复了 |