lists.openwall.net   lists  /  announce  owl-users  owl-dev  john-users  john-dev  passwdqc-users  yescrypt  popa3d-users  /  oss-security  kernel-hardening  musl  sabotage  tlsify  passwords  /  crypt-dev  xvendor  /  Bugtraq  Full-Disclosure  linux-kernel  linux-netdev  linux-ext4  linux-hardening  linux-cve-announce  PHC 
Open Source and information security mailing list archives
 
Hash Suite for Android: free password hash cracker in your pocket
[<prev] [next>] [thread-next>] [day] [month] [year] [list]
Date:	Wed, 22 Jul 2009 12:50:49 -0600
From:	"Chris Friesen" <cfriesen@...tel.com>
To:	linux-kernel@...r.kernel.org
Subject: question for C preprocessor wizards


I'm hoping someone can help me out.

I've got a bunch of code that call a bunch of different wrapper
routines, with varying numbers of arguments.  Depending on whether a
compile flag is set, I want to do some stuff before and after calling
the "real" routine.  I can do this easily enough with a macro.

#if FLAG
#define func_wrapper(args...) \
	do { \
		dostuff(); \
		func(args); \
		do_more_stuff(); \
	} while (0)
#else
#define func_wrapper(args...) func(args)
#endif


However, given that there are hundreds of functions, I'd like to
generate these macros with another macro, sort of like:

#if FLAG
#define WRAPPER(func) \
	#define func # _wrapper(args...) \
	do { \
		dostuff(); \
		func(args); \
		do_more_stuff(); \
	} while (0)
#else
#define WRAPPER(func) \
	#define func ## _wrapper(args...) func(args)
#endif

Where I could then do

WRAPPER(func1)
WRAPPER(func2)
...
WRAPPER(func100)


However, the preprocessor complains about having that "#" in the macro
body where it isn't used for stringification.


Anyone have any ideas how to accomplish this?  I had considered writing
an app to programmatically generate an include file as a precursor to
actually compiling the real app, but I was hoping there was a more
elegant solution.

Thanks,

Chris

--
To unsubscribe from this list: send the line "unsubscribe linux-kernel" in
the body of a message to majordomo@...r.kernel.org
More majordomo info at  http://vger.kernel.org/majordomo-info.html
Please read the FAQ at  http://www.tux.org/lkml/

Powered by blists - more mailing lists

Powered by Openwall GNU/*/Linux Powered by OpenVZ