🚀 go-pugleaf

RetroBBS NetNews Server

Inspired by RockSolid Light RIP Retro Guy

Article View: gnu.gcc.bug
Article #1471

varargs macros

#1471
From: John Salmon
Date: Thu, 24 Dec 1992 15:30
46 lines
2055 bytes
I'm not sure if this is a bug or a misunderstanding.  I am trying to
write a varargs macro 'Error', which adds __FILE__ and __LINE__
information to a printf-like argument list.  It works fine, except
when the "rest" argument is empty, in which case the ##rest
consrtuction deletes too much of the preceding text.  I expected the
##args construction to delete only the preceding comma, but instead,
it deletes the __LINE__ as well as the comma.  

Is this the "correct" behavior?  Is there a reason why the ##rest
construction should delete more than the previous comma?  Is there a
workaround?

Thanks,
John Salmon		 Internet: johns@delilah.ccsf.caltech.edu
206-49 Caltech		 UUCP: johns%delilah.ccsf.caltech.edu@uunet.uu.net
Pasadena, CA 91125 USA	 Bitnet: johns@caltech.bitnet
(818)356-2907		 delilah.ccsf.caltech.edu=[131.215.145.137]

delilah->cat junk.c
void volatile _Error(const char *, ...) 
     __attribute__ ((format (printf, 1, 2)));
#define Error(format, args...) \
    _Error(__FILE__ "(%d):" format, __LINE__ , ##args)

main(){
    Error("hello world");
    Error("Hello %s", "world");
}
delilah->gcc -E junk.c
# 1 "junk.c"
void volatile _Error(const char *, ...) 
     __attribute__ ((format (printf, 1, 2)));



main(){
    _Error("junk.c" "(%d):" "hello world") ;
    _Error("junk.c" "(%d):" "Hello %s", 8 ,"world") ;
}
delilah->

--
John Salmon		 Internet: johns@delilah.ccsf.caltech.edu
206-49 Caltech		 UUCP: johns%delilah.ccsf.caltech.edu@uunet.uu.net
Pasadena, CA 91125 USA	 Bitnet: johns@caltech.bitnet
(818)356-2907		 delilah.ccsf.caltech.edu=[131.215.145.137]
Technical Details
Message-ID: <JOHNS.92Dec24103027@delilah.ccsf.caltech.edu>
Path: arc1-ca.pugleaf.net!sparky!uunet!cis.ohio-state.edu!delilah.ccsf.caltech.edu!johns

Show Full Headers
Complete Article Headers
Newsgroups: gnu.gcc.bug
Path: arc1-ca.pugleaf.net!sparky!uunet!cis.ohio-state.edu!delilah.ccsf.caltech.edu!johns
From: johns@delilah.ccsf.caltech.edu (John Salmon)
Subject: varargs macros
Message-ID: <JOHNS.92Dec24103027@delilah.ccsf.caltech.edu>
Sender: gnulists@ai.mit.edu
Organization: Caltech Concurrent Supercomputing Facility.
Distribution: gnu
Date: Thu, 24 Dec 1992 15:30:27 GMT
Approved: bug-gcc@prep.ai.mit.edu
Lines: 47