Velocity Reviews - Computer Hardware Reviews

Velocity Reviews > Newsgroups > Programming > C Programming > Re: Preprocessor automation to define/declare array of strings

Reply
Thread Tools

Re: Preprocessor automation to define/declare array of strings

 
 
Ike Naar
Guest
Posts: n/a
 
      08-06-2012
On 2012-08-06, pozz <(E-Mail Removed)> 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.
 
Reply With Quote
 
 
 
Reply

Thread Tools

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are Off


Similar Threads
Thread Thread Starter Forum Replies Last Post
Re: Preprocessor automation to define/declare array of strings Eric Sosman C Programming 9 09-07-2012 08:49 PM
Re: Preprocessor automation to define/declare array of strings Jorgen Grahn C Programming 1 08-11-2012 05:31 PM
Supressing the ctrl-c and other keys during word automation in automation apondu ASP .Net 0 07-19-2007 09:10 PM
[netbeans] Changing preprocessor syntax automation (from old to new) marekdec Java 0 01-05-2007 08:41 AM
preprocessor, token concatenation, no valid preprocessor token Cronus C++ 1 07-14-2004 11:10 PM



Advertisments