mirror of
https://git.tartarus.org/simon/putty.git
synced 2025-01-09 17:38:00 +00: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:
parent
d13547d504
commit
3260e429a1
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 */
|
||||
|
@ -44,8 +44,6 @@
|
||||
#include <X11/Xatom.h>
|
||||
#endif
|
||||
|
||||
#define CAT2(x,y) x ## y
|
||||
#define CAT(x,y) CAT2(x,y)
|
||||
#define ASSERT(x) enum {CAT(assertion_,__LINE__) = 1 / (x)}
|
||||
|
||||
#if GTK_CHECK_VERSION(2,0,0)
|
||||
|
@ -144,8 +144,6 @@ static inline uintmax_t strtoumax(const char *nptr, char **endptr, int base)
|
||||
/* If you DECL_WINDOWS_FUNCTION as extern in a header file, use this to
|
||||
* define the function pointer in a source file */
|
||||
#define DEF_WINDOWS_FUNCTION(name) t_##name p_##name
|
||||
#define STR1(x) #x
|
||||
#define STR(x) STR1(x)
|
||||
#define GET_WINDOWS_FUNCTION_PP(module, name) \
|
||||
TYPECHECK((t_##name)NULL == name, \
|
||||
(p_##name = module ? \
|
||||
|
Loading…
Reference in New Issue
Block a user