由于VS2012没有支持inttypes.h,所以程序清单3.6无法编译通过,以下是我修改后的程序。修改a和b就可以了
/* altnames.c -- 可移植的整数类型名 */
#include <stdio.h>
//a.int16_t在VS2012的头文件是stdint.h,而不是inttypes.h
//#include <inttypes.h>
#include <stdint.h> //支持可移植类型
#define PRId16 "hd" //b.系统中没有定义,需要手动加入
int main (void)
{
int16_t mel16; //mel16是一个16位有符号变量
mel16 = 4593;
printf("First, assume int16_t is short:");
printf("mel16 = %hd\n", mel16);
printf("Next, let's not make any assumptions.\n");
printf("Instead, use a \"macro\" from inttypes.h:");
printf("mel16 = %" PRId16 "\n", mel16);
return 0;
}