mirror of
https://git.tartarus.org/simon/putty.git
synced 2025-06-30 19:12:48 -05:00
Move STR() and CAT() into defs.h.
I'm actually quite surprised there was only _one_ copy of each of these standard macros in the code base, given my general habit of casually redefining them anywhere I need them! But each one was in a silly place. Moved them up to the top level where they're available globally.
This commit is contained in:
24
defs.h
24
defs.h
@ -210,4 +210,28 @@ typedef struct PacketProtocolLayer PacketProtocolLayer;
|
||||
#define NORETURN
|
||||
#endif
|
||||
|
||||
/*
|
||||
* Standard macro definitions. STR() behaves like the preprocessor
|
||||
* stringification # operator, and CAT() behaves like the token paste
|
||||
* ## operator, except that each one macro-expands its argument(s)
|
||||
* first, unlike the raw version. E.g.
|
||||
*
|
||||
* #__LINE__ -> "__LINE__"
|
||||
* STR(__LINE__) -> "1234" (or whatever)
|
||||
*
|
||||
* and similarly,
|
||||
*
|
||||
* foo ## __LINE__ -> foo__LINE__
|
||||
* CAT(foo, __LINE__) -> foo1234 (or whatever)
|
||||
*
|
||||
* The expansion is achieved by having each macro pass its arguments
|
||||
* to a secondary inner macro, because parameter lists of a macro call
|
||||
* get expanded before the called macro is invoked. So STR(__LINE__)
|
||||
* -> STR_INNER(1234) -> #1234 -> "1234", and similarly for CAT.
|
||||
*/
|
||||
#define STR_INNER(x) #x
|
||||
#define STR(x) STR_INNER(x)
|
||||
#define CAT_INNER(x,y) x ## y
|
||||
#define CAT(x,y) CAT_INNER(x,y)
|
||||
|
||||
#endif /* PUTTY_DEFS_H */
|
||||
|
Reference in New Issue
Block a user