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

Python SQLAlchemy:AttributeError: Neither 'Column' object nor 'Comparator' object has an attribute 'schema' -

java - How not to audit a join table and related entities using Hibernate Envers? -

mongodb - CakePHP paginator ignoring order, but only for certain values -