Groups | Search | Server Info | Keyboard shortcuts | Login | Register [http] [https] [nntp] [nntps]
| From | Phil Carmody <thefatphil_demunged@yahoo.co.uk> |
|---|---|
| Newsgroups | comp.lang.c |
| Subject | Re: Preprocessor automation to define/declare array of strings |
| Date | 2012-08-10 11:35 +0300 |
| Organization | A noiseless patient Spider |
| Message-ID | <87mx23400u.fsf@bazspaz.fatphil.org> (permalink) |
| References | <jvojvp$vlg$1@news.newsland.it> <jvolm6$jti$1@dont-email.me> <jvomna$48e$1@news.newsland.it> <0.2dc85159ee187ef4ad8e.20120806182733BST.87wr1cylq2.fsf@bsb.me.uk> |
Ben Bacarisse <ben.usenet@bsb.me.uk> writes:
> pozzugno@gmail.com (pozz) writes:
> <snip>
> > And what if my "very old microcontroller" compiler doesn't support
> > variadic macros?
>
> In the common include write this:
>
> STRINGLIST(strlist_month) { "Jan", "Feb", "Mar" } EOL));
>
> and so on for each list. To get the .c file use:
>
> #define KILL(x)
> #define STRINGLIST(name) const char *name[] =
> #define EOL KILL((
>
> and to get the .h file use:
>
> #define KILL(x)
> #define STRINGLIST(name) extern const char *name[] KILL((
> #define EOL
>
> The "KILL" macro is the same.
I find that a little perverse with the parentheses divorced from their partners,
but not actually wrong. Perhaps "clever" is the most appropriate way of expressing
my worries about it.
For variety, I'm sure I encountered something like this in the past:
In one location define:
#define INTRO(name) const char *name[] = {
#define ELEMENT(s) s,
#define OUTRO };
In a different location define:
#define INTRO(name) extern const char *name[];
#define ELEMENT(s)
#define OUTRO
Which permits you do have files such as
INTRO(strlist_month)
ELEMENT("Jan")
ELEMENT("Feb")
...
OUTRO
I think when I saw it, the first thing that went through my mind was
#define INTRO(name) extern const char *name[0
#define ELEMENT(s) +1
#define OUTRO ]
such that the clients can know the size of the array, which means you don't need a
sentinal at the end, or a redundantly-provided source for that information.
However, I've not ever really needed to use the technique. I offer it just as
a new way of approaching the problem.
Phil
--
> I'd argue that there is much evidence for the existence of a God.
Pics or it didn't happen.
-- Tom (/. uid 822)
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