From: Shawn Hargreaves Newsgroups: comp.os.msdos.djgpp Subject: Re: allegro problems (gfx + kb) Date: Fri, 14 Mar 1997 20:12:44 +0000 Organization: None Distribution: world Message-ID: References: <199703122105 DOT VAA01257 AT post DOT dialin DOT co DOT uk> <5gb62v$h99 AT freenet-news DOT carleton DOT ca> NNTP-Posting-Host: talula.demon.co.uk MIME-Version: 1.0 Lines: 37 To: djgpp AT delorie DOT com DJ-Gateway: from newsgroup comp.os.msdos.djgpp Paul Derbyshire writes: >#define textoutf(b,f,fmt,x,y,c,args...) ({ char foobuf[256];\ > sprintf (foobuf,fmt, ## args);\ > textout (b,f,foobuf,x,y,c);\ > }) I actually already have such a routine in the version sitting on my hard drive, called textprintf (thanks to Ron T Lewis who suggested it). Thanks for the idea, anyway! >(I tried making this as a function and could not figure out how to pass a >runtime variable number of args to sprintf. I assumed just passing my It can be done with varargs and the vsprintf() function from libc. Personally I dislike using macros for things like this, because of the huge potential for unexpected side effects. Since gcc supports inline functions in C code, there really isn't any need to use macros... >#define trapmalloc(amt,type,errfunc) ({ type *fooptr;\ > fooptr=(type)malloc(amt*sizeof(type));\ > if (!fooptr) errfunc();\ > fooptr;\ Do you really think this is relevant to this group? By all means share your neat ideas with us, but on glancing through the posts sent to the group today, I notice that over a quarter of them are from you. Is there any chance you could filter your thoughts a bit, and only post the ones that seem particularly enlightening and/or relevant to djgpp? (please remember that general C coding issues are not included in the group charter). /* * Shawn Hargreaves - shawn AT talula DOT demon DOT co DOT uk - http://www.talula.demon.co.uk/ * Beauty is a French phonetic corruption of a short cloth neck ornament. */