I need to do something like this:
scanf("%ms", ...)
and compile it with
g++ -Wall -pedantic -std=c++11
also with
gcc -Wall -pedantic -std=c99
And it prints warning: ISO C does not support the 'm' scanf flag. How can i fix it?
I need to do something like this:
scanf("%ms", ...)
and compile it with
g++ -Wall -pedantic -std=c++11
also with
gcc -Wall -pedantic -std=c99
And it prints warning: ISO C does not support the 'm' scanf flag. How can i fix it?
Answer: Either drop -pedantic
, or give up %ms
. They don't come together.
AFAIK, there's nothing like %ms
format specifier in ISO C standards. It's added as an extension by POSIX.
The command line argument -pedantic
tells GCC to strictly follow the ISO C standards, so it won't accept %ms
with that option.
If your program is targeting POSIX systems, it'd be fine if you drop -pedantic
. Else if you want to make your code portable, don't use %ms
in printf
/scanf
.
The %ms
format is specified by POSIX, not by ISO C.
By using -Wall -pedantic -std=c99
, you've requested diagnostics for code that violates the C99 standard, as yours does (its behavior is undefined).
If you want your code to be portable to ISO C99 (or C11) implementations, don't use %ms
.
If you need to use %ms
(making your code less portable, but it should work with any POSIX-conforming implementation), don't use those options. Dropping the -pedantic
option seems to be sufficient to inhibit the warning. Compilers other than gcc are likely to have different options to achieve this (though clang copies gcc fairly closely).
The %ms notation is a POSIX extension in scanf() compared with the standard C version of scanf()