On Wed, 25 Oct 2000, you wrote:
> Hello Jeroen,
>
> I would _highly_ recommend to add the following little gcc-dependency to your
> source code. In FXString.h, line 228, change
>
> FXString& format(const char *fmt,...);
>
> to
>
> FXString& format(const char *fmt,...)
> #ifdef __GNUG__
> __attribute__((format (printf, 2, 3)))
> #endif
> ;
>
>
> If you do so, then gcc will parse the provided fmt string and check
> if the other arguments passed through ... are matching. This catches
> a lot of errors.
>
>
> (BTW yesterday I've seen a 0.000 displayed from a %.2f format
> -- beating dead horses :-))
>
> Ciao
> Dirk
Well, thanks again for the suggestion; I've implemented it and while
I found a number of harmless warnings, I did find one serious one
with a missing argument.
So it's been worth the effort already!
fxerror(), fxwarning(), fxmessage(), fxtrace(), FXMessageBox::error(), FXMessageBox::warning(),
FXMessageBox::question(), FXMessageBox::information(), FXString::format(), FXStringFormat()
are now all checked.
One little catch was that the "this" argument is included in the count.
To take advantage of this, compile your code with gcc and option -Wformat.
As I have done these with macros, if you define your own printf or scanf like
functions you can use these to macros to cause gcc to check the arguments
against the format:
FX_PRINTF(if,ia)
FX_SCANF(if,ia)
Where if is the index of the format string, ia is the index of the varargs.
the macros are defined as nothing on non-GCC machines.
Regards,
Jeroen
--
+-------------------------------+--------------------------------------------+
| E-Mail : jvz@... | The FOX Platform Independent GUI Toolkit: |
| USMail : 215 Wynn Drive, | |
| Huntsville, AL 35805 | Official Site: |
| Phone : (256) 726-4820 | http://www.cfdrc.com/FOX/fox.html |
| Fax : (256) 726-4806 | ftp://ftp.cfdrc.com/pub/FOX |
| WWW : http://www.cfdrc.com | |
+-------------------------------+--------------------------------------------+
| Copyright (C) 10:30 10/25/2000 Jeroen van der Zijp. All Rights Reserved. |
+----------------------------------------------------------------------------+
|