Path: utzoo!utgpu!watmath!clyde!att!osu-cis!tut.cis.ohio-state.edu!mailrus!uflorida!gatech!mcnc!duke!romeo!khera From: khera@romeo.cs.duke.edu (Vick Khera) Newsgroups: comp.lang.c Subject: Re: how widespread is this cpp bug? Summary: it is useful... Keywords: cpp whitespace bug Message-ID: <12967@duke.cs.duke.edu> Date: 1 Dec 88 23:27:04 GMT References: <49179@pyramid.pyramid.com> Sender: news@duke.cs.duke.edu Reply-To: khera@romeo.UUCP (Vick Khera) Organization: Duke University CS Dept.; Durham, NC Lines: 74 In article <49179@pyramid.pyramid.com> markhall@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@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@cs.duke.edu Department of Computer Science CSNET: khera@duke Duke University UUCP: decvax!duke!khera Durham, NC 27706