<html><head><meta http-equiv="Content-Type" content="text/html; charset=utf-8"></head><body style="word-wrap: break-word; -webkit-nbsp-mode: space; line-break: after-white-space;" class=""><br class=""><div><blockquote type="cite" class=""><div class="">On Aug 21, 2019, at 05:36, Forumer 4umer via cfe-users <<a href="mailto:cfe-users@lists.llvm.org" class="">cfe-users@lists.llvm.org</a>> wrote:</div><br class="Apple-interchange-newline"><div class=""><div class="">So a bit more explanation, the macros are used to generate data structure and methods and the following definition is used to declare a structure:<br class=""><br class="">DEF_STRUCT(namedDate, namedDate, (std::string, name), (std::time_t, date))<br class=""><br class="">On visual when I look at preprocessed file I get this (focus on line starting with struct namedDate) :<br class=""><br class="">namespace LibTech<br class="">{<br class=""> namespace DataTypes<br class=""> {<br class=""> #line 1 "E:\\DEV\\FixMacroOnClang\\DeclareDatatypes.h"<br class=""> #line 17 "E:\\DEV\\FixMacroOnClang\\DeclareDatatypes.h"<br class=""> #line 12 "E:\\DEV\\FixMacroOnClang\\Protocol.h"<br class=""> #line 1 "E:\\DEV\\FixMacroOnClang\\DataTypesDef.h"<br class=""><br class="">struct namedDate{ std::string name; std::time_t date; };<br class=""><br class=""> #line 13 "E:\\DEV\\FixMacroOnClang\\Protocol.h"<br class=""> #line 1 "E:\\DEV\\FixMacroOnClang\\DeclareDatatypes.h"<br class=""><span class="Apple-tab-span" style="white-space:pre"> </span> #line 1 "E:\\DEV\\FixMacroOnClang\\macro\\UndefDataTypesDef.h"<br class=""><span class="Apple-tab-span" style="white-space:pre"> </span> #line 14 "E:\\DEV\\FixMacroOnClang\\DeclareDatatypes.h"<br class=""><span class="Apple-tab-span" style="white-space:pre"> </span> #line 17 "E:\\DEV\\FixMacroOnClang\\DeclareDatatypes.h"<br class=""><span class="Apple-tab-span" style="white-space:pre"> </span> #line 14 "E:\\DEV\\FixMacroOnClang\\Protocol.h"<br class=""> }<br class=""><br class="">}<br class=""><br class="">but when using clang I have this:<br class=""><br class="">namespace LibTech<br class="">{<br class=""> namespace DataTypes<br class=""> {<br class=""> # 1 "E:\\DEV\\FixMacroOnClang/DeclareDatatypes.h" 1<br class=""> # 12 "E:\\DEV\\FixMacroOnClang/Protocol.h" 2<br class=""> # 1 "E:\\DEV\\FixMacroOnClang/DataTypesDef.h" 1<br class=""><br class="">struct namedDate{ PP_GS 2 (TO_FIELD, (std::string, name), (std::time_t, date)) };<br class=""><br class=""> # 13 "E:\\DEV\\FixMacroOnClang/Protocol.h" 2<br class=""> # 1 "E:\\DEV\\FixMacroOnClang/DeclareDatatypes.h" 1<br class=""> # 13 "E:\\DEV\\FixMacroOnClang/DeclareDatatypes.h"<br class=""> # 1 "E:\\DEV\\FixMacroOnClang/./macro/UndefDataTypesDef.h" 1<br class=""> # 14 "E:\\DEV\\FixMacroOnClang/DeclareDatatypes.h" 2<br class=""> # 14 "E:\\DEV\\FixMacroOnClang/Protocol.h" 2<br class=""> }<br class="">}<br class=""><br class="">as you can see the macros used inside preprocessor.h doesn't work with clang I have macro PP_GS and TO_FIELD macros that are not expanded.<br class=""><br class="">I cannot copy/paste all macro definitions because it won't be very easy to read but here is how it starts:<br class=""><br class="">#ifndef DEF_ID_BEGIN<br class=""><br class="">//...<br class=""><br class="">#define TO_FIELD(type, name) type name;<br class="">#define DEF_STRUCT(type, dataTypeId, ...) struct type{ PP_FOREACH_GROUP(TO_FIELD,__VA_ARGS__) };<br class=""><br class="">#else<br class=""><br class="">#include "./macro/UndefDataTypesDef.h"<br class="">#undef TO_FIELD<br class=""><br class="">#endif<br class=""><br class="">and inside preprocessor.h<br class=""><br class="">#define PP_PREFIX(Method) PP_##Method<br class="">#define PP_SUFFIX(N) N<br class="">#define PP_ENTRY(Method,N) PP_PREFIX(Method)PP_SUFFIX(N)<br class="">#define PP_CALL_PP_SN( Method, Func, N, ...) PP_ENTRY(Method,N) PP_FW(Func, __VA_ARGS__)<br class=""><br class="">#define PP_FOREACH(Func, ...) PP_CALL_PP_SN( S, Func, PP_ARGCOUNT PP_FW(__VA_ARGS__), __VA_ARGS__ )<br class="">#define PP_FOREACH_GROUP(Func, ...) PP_CALL_PP_SN( GS, Func, PP_ARGCOUNT PP_FW(__VA_ARGS__), __VA_ARGS__ )<br class=""><br class=""><br class="">#define PP_RSEQ_N()\<br class="">63 ,62 ,61 ,60 ,\<br class="">59 ,58 ,57 ,56 ,55 ,54 ,53 ,52 ,51 ,50 ,\<br class="">49 ,48 ,47 ,46 ,45 ,44 ,43 ,42 ,41 ,40 ,\<br class="">39 ,38 ,37 ,36 ,35 ,34 ,33 ,32 ,31 ,30 ,\<br class="">29 ,28 ,27 ,26 ,25 ,24 ,23 ,22 ,21 ,20 ,\<br class="">19 ,18 ,17 ,16 ,15 ,14 ,13 ,12 ,11 ,10 ,\<br class="">9,8,7,6,5,4,3,2,1,0<br class=""><br class="">#define PP_ARG_N( \<br class="">_1 ,_2 ,_3 ,_4 ,_5 ,_6 ,_7 ,_8 ,_9 ,_10 ,\<br class="">_11 ,_12 ,_13 ,_14 ,_15 ,_16 ,_17 ,_18 ,_19 ,_20 ,\<br class="">_21 ,_22 ,_23 ,_24 ,_25 ,_26 ,_27 ,_28 ,_29 ,_30 ,\<br class="">_31 ,_32 ,_33 ,_34 ,_35 ,_36 ,_37 ,_38 ,_39 ,_40 ,\<br class="">_41 ,_42 ,_43 ,_44 ,_45 ,_46 ,_47 ,_48 ,_49 ,_50 ,\<br class="">_51 ,_52 ,_53 ,_54 ,_55 ,_56 ,_57 ,_58 ,_59 ,_60 ,\<br class="">_61 ,_62 ,_63 , N , ...) N<br class=""><br class="">#define PP_FW(...) (__VA_ARGS__)<br class="">#define PP_NARG_(...) PP_ARG_N PP_FW(__VA_ARGS__)<br class="">#define PP_ARGCOUNT(...) PP_NARG_(__VA_ARGS__,PP_RSEQ_N())<br class=""><br class="">but have a look here to see all the macros: <a href="https://github.com/vrichomme/FixMacroOnClang/blob/master/preprocessor.h" class="">https://github.com/vrichomme/FixMacroOnClang/blob/master/preprocessor.h</a><br class=""><br class="">Maybe one of the problem is with PP_FW(...) but not sure about that…</div></div></blockquote></div><br class=""><div class="">It seems like there are two problems: (1) TO_FIELD comes out with a trailing comma and so does not get expanded and (2) PP_GS and 2 tokens are not joined which would also impeded further expansion. I would expect to see a further ## somewhere in your macros. It looks like you’re using [0] when maybe you want something more like [1]?</div><div class=""><br class=""></div><div class=""> [0]: <a href="https://groups.google.com/forum/#!topic/comp.std.c/d-6Mj5Lko_s" class="">https://groups.google.com/forum/#!topic/comp.std.c/d-6Mj5Lko_s</a></div><div class=""> [1]: <a href="https://stackoverflow.com/questions/11761703/overloading-macro-on-number-of-arguments" class="">https://stackoverflow.com/questions/11761703/overloading-macro-on-number-of-arguments</a></div><div class=""><br class=""></div></body></html>