size of a datatype without using sizeof

后端 未结 21 2003
慢半拍i
慢半拍i 2020-12-01 02:34

I have a data type, say X, and I want to know its size without declaring a variable or pointer of that type and of course without using sizeof oper

21条回答
  •  心在旅途
    2020-12-01 02:58

    if X is datatype:

    #define SIZEOF(X) (unsigned int)( (X *)0+1 )
    

    if X is a variable:

    #define SIZEOF(X) (unsigned int)( (char *)(&X+1)-(char *)(&X) )
    

提交回复
热议问题