This is the mail archive of the
gcc-help@gcc.gnu.org
mailing list for the GCC project.
Re: Use -Wformat for own functions?
- From: Mihnea Balta <dark_lkml at mymail dot ro>
- To: "Bo Do" <bodo at flygp dot se>, <gcc-help at gcc dot gnu dot org>
- Date: Wed, 12 Nov 2003 13:10:41 +0200
- Subject: Re: Use -Wformat for own functions?
- References: <00a901c3a90d$86c2fae0$2bfb0ec2@flygp.se>
void l_log(const char* fmt, ...) __attribute__ ((format (printf, 1, 2)));
The first argument of __attribute__(format) is the kind of format string to
expect (printf, scanf, strftime). The second is the index of the format
string argument. The third is the index of the first variable argument. In
your case:
int my_sprintf(MyBuffer, const char *format, ...) __attribute__ ((format
(printf, 2, 3)));
If the function is a member of a class, the indices must be shifted by 1, as
the compiler passes "this" as the first function argument. For example:
class something{
public:
int my_sprintf(MyBuffer, const char *format, ...) __attribute__ ((format
(printf, 3, 4)));
};
Have fun.
On Wednesday 12 November 2003 13:10, Bo Do wrote:
> Hello all!
>
> I've written my own version of sprintf:
> my_sprintf(MyBuffer, const char *format, ...)
> I wonder if there's a way to use -Wformat, or any functionality of the
> compiler, to make sure that the number of arguments supplied (the ... ) are
> correct and have types appropriate to the format string specified. -Wformat
> has the functionality I want, but it only checks the printf and scanf
> functions in stdio.
>
> Thanks for any hints or help.
> /Bo
>
>
> ---------------------------------------------------------------
> Acasa.ro vine cu albumele, tu vino doar cu pozele ;)
> http://poze.acasa.ro/