[coreboot] need help with #define macro

Joseph Smith joe at settoplinux.org
Mon Dec 22 22:23:15 CET 2008




On Mon, 22 Dec 2008 08:47:28 -0800, "ron minnich" <rminnich at gmail.com>
wrote:
> On Sat, Dec 20, 2008 at 11:45 AM, Joseph Smith <joe at settoplinux.org>
wrote:
>>
>> Hello,
>> I'm trying to setup a #define macro that can be used through out the
>> program and also part of another macro. I know this won't work but you
> may
>> get the idea of what I am trying to do:
>>
>> #define PARALLEL_PORT parport0
>> #define PARPORT_BASE_FILE
> "/proc/sys/dev/parport/"PARALLEL_PORT"/base-addr"
>> ...
>> ...
>> fd = open("/dev/PARALLEL_PORT",O_RDWR);
>> ...
>> printf(PARPORT_BASE_FILE\n);
>> ...
> 
> you can do this kind of magic. I frown on it. Why? Because it is
> 1. not totally portable
> 2. saving time on a one-time operation which takes a trivial amount of
> time
> 3. over-emphasizing cpp magic, which is way overdone nowadays.
> 4. inflexible; why are you hard-coding a parallel port name at compile
> time? What if you need to use a different one-- what do you do,
> recompile the program?
> 
> An easy and portable and flexible way to do this:
> char *partport = "parport0";
> static char parportname[MAXPATHLEN];
> 
> sprintf(parportname, "/proc/sys/dev/parport/%s/base-addr", parport );
> 
> now add the code to set parport at runtime based on options.
> 
> In general, but especially for those things which can change, it's a
> very bad idea to hard-code them in cpp magic.
> 
> Of course, this code is still very linux specific, but ...
> 
Excellent, Thanks Ron :-)
That's the kind of help I am talking about :-)

-- 
Thanks,
Joseph Smith
Set-Top-Linux
www.settoplinux.org





More information about the coreboot mailing list