taozhijiang <taozhiji...@gmail.com> writes: > I want to using #define / #undef, and want to put them in a single > macro, some thing like:
> #define DECALRE_TYPE(type) \ > { #undef __curr_type; #define _curr_type type; } > as we know, this can not passed with CPP, but I need this logical here. I'm afraid the answer is that you can't do that, since it's not part of the C programming language. You can't use macro parameters in #define that way because #define processing happens at too early of a stage in the compilation process. > Generally, the problem comes from > #define ser_field(type, var) \ > ser_new_field(tra, #type, #var, offsetof(struct_type, var)) > I do not want another additional parameter in this macro like > #define ser_field(type,var,struct_type), and I want a sentence declare > "current struct type" > and all later work of ser_field will defaultly use this type. You can #undef and then #define the ser_field macro with a different struct_type. I think that's the best solution you'll be able to get while using only the C preprocessor. -- Russ Allbery (r...@debian.org) <http://www.eyrie.org/~eagle/> -- To UNSUBSCRIBE, email to debian-devel-requ...@lists.debian.org with a subject of "unsubscribe". Trouble? Contact listmas...@lists.debian.org Archive: http://lists.debian.org/8761qwva9o....@windlord.stanford.edu