<stddef.h>

Common definitions

定义类型:

ptrdiff_t 两指针相减的结果,signed integer

size_t sizeof操作符的结果,unsigned integer

max_align_t 和实际支持的alignment一样大的对象类型

wchar_t 能够表示所有最大扩展字符集的编码值,integer

定义宏:

NULL 空指针常量

offsetof(type, member-designator) 求结构体成员的偏移量,若是位域,则是未定义行为

// gcc -std=c11 test_stddef.c
#include <stddef.h>

struct S {
  int a;
  int b;
};

int main() {
  struct S s[10];
  struct S* pa1 = &s[2], * pa2 = &s[7];
  ptrdiff_t diff = pa2 - pa1;
  max_align_t m;
  size_t size = sizeof(m);
  wchar_t code = '';
  pa1 = NULL;
  size_t offset = offsetof(struct S, b);

  return 0;
}

 

posted on 2013-10-08 12:32  chenkkkabc  阅读(470)  评论(0编辑  收藏  举报