Created
November 16, 2016 18:57
-
-
Save edenhill/df22db10f366258c743eeaee02c6e644 to your computer and use it in GitHub Desktop.
compile time type checking
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#define _LRK_TYPECHECK(RET,TYPE,ARG) \ | |
({ \ | |
if (0) { \ | |
TYPE __t RD_UNUSED = (ARG); \ | |
} \ | |
RET; \ | |
}) | |
#define _LRK_TYPECHECK2(RET,TYPE,ARG,TYPE2,ARG2) \ | |
({ \ | |
if (0) { \ | |
TYPE __t RD_UNUSED = (ARG); \ | |
TYPE2 __t2 RD_UNUSED = (ARG2); \ | |
} \ | |
RET; \ | |
}) | |
#define RD_KAFKA_V_END RD_KAFKA_VTYPE_END | |
#define RD_KAFKA_V_TOPIC(topic) \ | |
_LRK_TYPECHECK(RD_KAFKA_VTYPE_TOPIC, const char *, topic), topic | |
#define RD_KAFKA_V_VALUE(VALUE,LEN) \ | |
_LRK_TYPECHECK2(RD_KAFKA_VTYPE_VALUE, void *, VALUE, size_t, LEN), \ | |
VALUE, LEN | |
// gives: | |
0052-msg_timestamps.c: In function ‘produce_msgs’: | |
0052-msg_timestamps.c:80:58: error: incompatible types when initializing type ‘const char *’ using type ‘rd_kafka_resp_err_t {aka enum <anonymous>}’ | |
RD_KAFKA_V_TOPIC(err), | |
^ | |
../src/rdkafka.h:2353:46: note: in definition of macro ‘_LRK_TYPECHECK’ | |
TYPE __t RD_UNUSED = ARG; \ | |
^ | |
0052-msg_timestamps.c:80:41: note: in expansion of macro ‘RD_KAFKA_V_TOPIC’ | |
RD_KAFKA_V_TOPIC(err), | |
^ | |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment