Add macros for diagnostic control, use for scanf %a tests
Paul Eggert
eggert@cs.ucla.edu
Wed Nov 26 00:36:00 GMT 2014
Joseph Myers wrote:
> + /* GCC in C99 mode treats %a as the C99 format expecting float *,
> + but glibc with _GNU_SOURCE treats %as as the GNU allocation
> + extension, so resulting in "warning: format '%a' expects argument
> + of type 'float *', but argument 3 has type 'char **'". This
> + applies to the other %as, %aS and %a[] formats below as well. */
> + DIAG_PUSH_NEEDS_COMMENT;
> + DIAG_IGNORE_NEEDS_COMMENT (4.9, "-Wformat");
> if (sscanf (" 1.25s x", "%as%2c", &sp, c) != 2)
> FAIL ();
> else
> @@ -32,10 +40,14 @@ main (void)
> memset (sp, 'x', sizeof "1.25s");
> free (sp);
> }
> + DIAG_POP_NEEDS_COMMENT;
This sort of thing looks intrusive. Instead, how about defining a macro
'C99_sscanf' that does the push and pop and commentary, and then simply
replacing warned-about uses of sscanf with C99_scanf? That'd be a lot easier to
read, and it's more along the lines of Roland's original suggestion.
More information about the Libc-alpha
mailing list