Groups | Search | Server Info | Keyboard shortcuts | Login | Register [http] [https] [nntp] [nntps]
| From | Ike Naar <ike@faeroes.freeshell.org> |
|---|---|
| Newsgroups | comp.lang.c |
| Subject | Re: Preprocessor automation to define/declare array of strings |
| Date | 2012-08-06 14:55 +0000 |
| Organization | A noiseless patient Spider |
| Message-ID | <slrn3vfsk1vmmu.6e7.ike@faeroes.freeshell.org> (permalink) |
| References | <jvojvp$vlg$1@news.newsland.it> |
On 2012-08-06, pozz <pozzugno@gmail.com> wrote:
> I was thinking to automate the declaration/definition of lists of strings
> through C preprocessor. For example:
>
> --- defstrings.def ---
> STRINGLIST(strlist_month, { "Jan", "Feb", ... } );
> STRINGLIST(strlist_day, { "Mon", "Thu", ... } );
> STRINGLIST(strlist_onoff, { "ON", "OFF", ... } );
> --- defstrings.c ---
> #define STRINGLIST(name, list) const char *name[] = list;
This will not work. The macro takes two parameters,
but it is called with more than two arguments, e.g. in
STRINGLIST(strlist_onoff, { "ON", "OFF" } );
there are three arguments,
strlist_onoff /* first */
{ "ON" /* second */
"OFF" } /* third */
This could be fixed using a variable arguments macro,
#define STRINGLIST(name, ...) const char *name[] = __VA_ARGS__;
Another issue: perhaps it would be better to drop the terminating
semicolon from the macro definition, because if the macro is called
the way you do it, the result will have two terminating semicolons
which may cause syntax errors.
Back to comp.lang.c | Previous | Next — Previous in thread | Next in thread | Find similar | Unroll thread
Preprocessor automation to define/declare array of strings pozzugno@gmail.com (pozz) - 2012-08-06 16:23 +0200
Re: Preprocessor automation to define/declare array of strings Eric Sosman <esosman@ieee-dot-org.invalid> - 2012-08-06 10:51 -0400
Re: Preprocessor automation to define/declare array of strings Eric Sosman <esosman@ieee-dot-org.invalid> - 2012-08-06 11:01 -0400
Re: Preprocessor automation to define/declare array of strings pozzugno@gmail.com (pozz) - 2012-08-06 17:10 +0200
Re: Preprocessor automation to define/declare array of strings Eric Sosman <esosman@ieee-dot-org.invalid> - 2012-08-06 12:51 -0400
Re: Preprocessor automation to define/declare array of strings Ben Bacarisse <ben.usenet@bsb.me.uk> - 2012-08-06 18:27 +0100
Re: Preprocessor automation to define/declare array of strings Phil Carmody <thefatphil_demunged@yahoo.co.uk> - 2012-08-10 11:35 +0300
OT (Re: Preprocessor automation to define/declare array of strings) Mark Bluemel <mark_bluemel@pobox.com> - 2012-08-10 09:56 +0100
Re: OT (Re: Preprocessor automation to define/declare array of strings) Phil Carmody <thefatphil_demunged@yahoo.co.uk> - 2012-08-12 02:38 +0300
Re: Preprocessor automation to define/declare array of strings Ben Bacarisse <ben.usenet@bsb.me.uk> - 2012-08-10 12:45 +0100
Re: Preprocessor automation to define/declare array of strings Nick Keighley <nick_keighley_nospam@hotmail.com> - 2012-08-07 00:16 -0700
Re: Preprocessor automation to define/declare array of strings Tim Rentsch <txr@alumni.caltech.edu> - 2012-09-07 13:49 -0700
Re: Preprocessor automation to define/declare array of strings Ike Naar <ike@faeroes.freeshell.org> - 2012-08-06 14:55 +0000
Re: Preprocessor automation to define/declare array of strings Jorgen Grahn <grahn+nntp@snipabacken.se> - 2012-08-11 06:09 +0000
csiph-web