From: bernd@petrovitsch.priv.at (Bernd Petrovitsch)
To: kernelnewbies@lists.kernelnewbies.org
Subject: How to define function-like macro?
Date: Tue, 26 Nov 2013 13:50:31 +0100 [thread overview]
Message-ID: <1385470231.29113.53.camel@thorin> (raw)
In-Reply-To: <CAJFpruKYyj6OMxfgPvRV_gS2BMN=EWnDrz8dEk_ucL-Ha9pF6A@mail.gmail.com>
On Die, 2013-11-26 at 10:50 +0800, ??? wrote:
> I read manual already:
>
> -D name=definition The contents of definition are tokenized and processed
> as if they appeared during translation phase three in a ?#define?
> directive. In particular, the definition will be truncated by embedded
> newline characters.
>
> If you are invoking the preprocessor from a shell or shell-like program you
> may need to use the shell's quoting syntax to protect characters such as
> spaces that have a meaning in the shell syntax.
>
> If you wish to define a function-like macro on the command line, write its
> argument list with surrounding parentheses before the equals sign (if any).
> Parentheses are meaningful to most shells, so you will need to quote the
> option. With sh and csh, -D'name(args...)=definition' works.
> I wrote this in my makefile:
>
> *def_dpf = 'dpf(a...)=printk(KERN_ALERT a)'*
Variadic macros needs something slightly different on the right side -
see also http://gcc.gnu.org/onlinedocs/cpp/Variadic-Macros.html (if we
assume gcc).
Send the gcc invocation or at least a real snippet of the real Makefile
so that no one has to guess what's really there (and where).
At least - following the above "manual": -D'dpf(...)=printk(KERN_ALERT
__VA_ARGS__)'
Though I write such macros more like
-D'dpf(fmt, ...)=printk(KERN_ALERT fmt, __VA_ARGS__)'
if only for clarity.
> My code uses `dpf` macro like this:
>
> *dpf("current value=%d\n",var);*
>
> When I compiling my program, I got this error:
>
> *error: ?Da? undeclared (first use in this function)*
No idea where the 'Da' could come from. Which leads to the conclusion
that at least comething is missing ....
> Even manual says *sh* and *csh* can works with that definition,
It' just about the quoting and pretty any shell should work with
single-quotes.
If not, you need to fix the Makefile - you can set the shell to be used
there.
> *bash*should support that machanism, I guess. How should I do? Any
> suggestion?
And what has that to do with any/the shell?
Kind regards,
Bernd
--
Bernd Petrovitsch Email : bernd at petrovitsch.priv.at
LUGA : http://www.luga.at
prev parent reply other threads:[~2013-11-26 12:50 UTC|newest]
Thread overview: 2+ messages / expand[flat|nested] mbox.gz Atom feed top
2013-11-26 2:50 How to define function-like macro? 乃宏周
2013-11-26 12:50 ` Bernd Petrovitsch [this message]
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=1385470231.29113.53.camel@thorin \
--to=bernd@petrovitsch.priv.at \
--cc=kernelnewbies@lists.kernelnewbies.org \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).