Re: #ifdef statement inside #define

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

 



On Fri, 2006-08-18 at 15:01 +0200, Katharina Denkinger wrote:
> Has anyone an idea how to code following macro:

Yes. It can be found in every decent C tutorial:

> #define INIT()    \
>     #ifdef THREDSAFE        \
>               lock_mutex()   \
>     #endif    \

#ifdef THREDSAFE
#define INIT() lock_mutex()
#else
#define INIT()
#endif

> The error ist that after a # operator there is an parameter expected.
> The normal escape doesn't help in this case.

Yes. The preprocessor replace INIT() with the #ifdef stuff and the
(real) C compiler (which uses the preprocessors output) barfs on #ifdef.

	Bernd
-- 
Firmix Software GmbH                   http://www.firmix.at/
mobil: +43 664 4416156                 fax: +43 1 7890849-55
          Embedded Linux Development and Services


--
Kernelnewbies: Help each other learn about the Linux kernel.
Archive:       http://mail.nl.linux.org/kernelnewbies/
FAQ:           http://kernelnewbies.org/faq/


[Index of Archives]     [Newbies FAQ]     [Linux Kernel Mentors]     [Linux Kernel Development]     [IETF Annouce]     [Git]     [Networking]     [Security]     [Bugtraq]     [Yosemite]     [MIPS Linux]     [ARM Linux]     [Linux RAID]     [Linux SCSI]     [Linux ACPI]
  Powered by Linux