|
From: | PAZ |
Subject: | [avr-gcc-list] Question regarding the format attribute |
Date: | Wed, 24 Jan 2007 09:38:52 +0200 |
One really useful feature of the gcc compiler is the ability
to check whether the arguments in a ‘printf’ like function correspond
with its format string: int MY_printf(char *format, ...)
__attribute__((format (printf,1,2))); This will generate a warning if the function is called for
example like ‘MY_printf(”%s”, 1234);’ Unfortunately, this feature does not work when program
memory constants are used in the definition: int MY_printf(PGM_P *format, ...)
__attribute__((format (printf,1,2))); The call ‘MY_printf(PSTR(”%s”), 1234);’
no longer gives the desired warning that there is a mismatch between the printf
like format and the argument list. This can be explained by arguing that a ‘printf’
formatted function must have a (char *) argument for its specified format
parameter. It’s a real bummer though that the format attribute
does not work with functions that are declared as above. Note that the compiler
does not throw a error if you do. Any thoughts ? Regards Peter |
[Prev in Thread] | Current Thread | [Next in Thread] |