Re: C++ probs (__GNU_C__?)

From: Erwin S. Andreasen (erwin@PIP.DKNET.DK)
Date: 12/09/97


On Tue, 9 Dec 1997, Akuma/Chris Baggett/DOOMer wrote:



>
> comm.h:24: format string arg not a string type
>
> #ifdef __GNUC__
> void char_data::printf(const char *messg, ...)
>         __attribute__ ((format (printf, 1, 2)));  // <-- Line 24
> #else
> void char_data::printf(const char *messg, ...);
> #endif
>
> what does that mean?

the "format" attribute extension is a way of telling gcc that it should
check the arguments like it would for printf, i.e. that it should warn you
if you do stuff like:

ch->printf ("Gold: %d\n", some_string);

printf means: check for printf-like argument list (i.e. %d should be an
int)

scanf can also appear there, meaning that the function works like scanf
(i.e. %d expects a int*)

The second paramter is where the format string is.
The third paramter is where the arguments begin.

However, in case of member functions, gcc also counts the hidden pointer
to the object as the first parameter!

So, this should be: __attribute__ ((format(printf, 2,3)))

 =============================================================================
Erwin Andreasen   Herlev, Denmark <erwin@pip.dknet.dk>  UNIX System Programmer
<URL:http://www.abandoned.org/drylock/>     <*>         (not speaking for) DDE
 =============================================================================


     +------------------------------------------------------------+
     | Ensure that you have read the CircleMUD Mailing List FAQ:  |
     | http://democracy.queensu.ca/~fletcher/Circle/list-faq.html |
     +------------------------------------------------------------+



This archive was generated by hypermail 2b30 : 12/08/00 PST