Message263982
It is possible to implement type checking in C macros.
Example found on the Internet:
/* inline type checking - can mix in with other macros more easily using the comma operator,
* C11 gives best results here */
#if defined(__STDC_VERSION__) && (__STDC_VERSION__ >= 201112L)
# define CHECK_TYPE_INLINE(val, type) \
(void)((void)(((type)0) != (0 ? (val) : ((type)0))), \
_Generic((val), type: 0, const type: 0))
#else
# define CHECK_TYPE_INLINE(val, type) \
((void)(((type)0) != (0 ? (val) : ((type)0))))
#endif
http://stackoverflow.com/questions/11449632/checking-types-of-macro-parameters-at-compile-time
See also Include/pymacro.h which contains some macros implementing checks tested at the compilation. |
|
Date |
User |
Action |
Args |
2016-04-22 08:17:45 | vstinner | set | recipients:
+ vstinner, loewis, rhettinger, ned.deily, martin.panter, serhiy.storchaka, xiang.zhang |
2016-04-22 08:17:45 | vstinner | set | messageid: <1461313065.01.0.548513976392.issue26824@psf.upfronthosting.co.za> |
2016-04-22 08:17:45 | vstinner | link | issue26824 messages |
2016-04-22 08:17:44 | vstinner | create | |
|