c - Checking types of macro parameters at compile time -


To test that two variables have the same structure type I use macros

  #define  

If some function-like macros

#finem (A, B) blockabla

Believe that A and B should be of the same composition type, I combine a compile time probe:

  # defined M (A, B ) (Assert_same_struct_types (a, b), blablabla)  

which stimulates compiler error if MK collar ( A, B) accidentally passes different types of stranks.

However, this approach does not always work due to built-in conversions between them and works for pointer types.

So, it is probably not possible to solve this problem for arbitrary type of Structs?

I need a solution of C89, however, it would be interesting to hear about the CAM or C11 prospects.

  define aSSERT_SAME_TYPE (a, b) ((zero) (& amp; ( A) == & amp; (B)))  

You will get an error with a compiled diagnostic and - Terror ( GCC < / Code> or for the same options for other compilers).

Note that many compilers have non-standard extension operators to get type of objects and it can be used to check two types.


Comments

Popular posts from this blog

java - NullPointerException for a 2d Array -

python - Assemble mpeg file unable to play in mediaplayer -

c# - NameSpace Manager or XsltContent to parse aspx page -