how widespread is this cpp bug?
Vick Khera
khera at romeo.cs.duke.edu
Fri Dec 2 09:27:04 AEST 1988
In article <49179 at pyramid.pyramid.com> markhall at pyramid.UUCP (Mark Hall) writes:
>The following code compiles and runs on pyramid, att-3b2, and sun3:
> ...
>But, according to K&R pg. 179:
>
> ``... comments [...] as described below
> are ignored except as they serve to separate tokens.''
>
> ...
>I hear that
>this `feature' is used for gluing togehter tokens, as in:
>
>#define VERSION 2
>main() {
> proc/**/VERSION( a,b,c );
>}
>
>-Mark Hall (smart mailer): markhall at pyramid.pyramid.com
> (uucp paths): {ames|decwrl|sun|seismo}!pyramid!markhall
I have used this ``feature'' to simplify having to write a bunch of
duplicate code with a macro. what i needed was a bunch of buttons that had
a particular label and when pressed, would call the function with a name
based on the button label. for example, the button labeled ``inc'' would
call inc_proc(). the comment is used to delimit the tokens as far as the
pre-processor is concerned, but when the compiler gets it, it needs to be
one token. how else would this macro be constructed?
excerpts from a sunview application:
-----
#define BUTTON_WIDTH 8 /* width for command buttons */
#define cmd_button(fnc) \
panel_create_item(bs_panel, PANEL_BUTTON, \
PANEL_LABEL_IMAGE, panel_button_image(bs_panel, \
"fnc",BUTTON_WIDTH,0), \
PANEL_LABEL_BOLD, TRUE, \
PANEL_NOTIFY_PROC, fnc/**/_proc, \
0)
main(argc,argv)
int argc;
char *argv[];
{
[ bunches of window creating code delted... ]
cmd_button(ali); /* create the actual buttons */
cmd_button(comp);
cmd_button(forw);
cmd_button(inc);
cmd_button(msgchk);
cmd_button(next);
cmd_button(prev);
cmd_button(refile);
cmd_button(repl);
cmd_button(rmm);
cmd_button(scan);
cmd_button(show);
cmd_button(sortm);
cmd_button(folders);
cmd_button(rne); /* rmm;next */
cmd_button(rpr); /* rmm;prev */
[ bunches more code deleted. ]
}
=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=
ARPA: khera at cs.duke.edu Department of Computer Science
CSNET: khera at duke Duke University
UUCP: decvax!duke!khera Durham, NC 27706
More information about the Comp.lang.c
mailing list