How to fix warning with %ms in scanf
I need to do something like this:
and compile it with
g++ -Wall -pedantic -std=c++11
gcc -Wall -pedantic -std=c99
And it prints warning: ISO C does not support the 'm' scanf flag. How can i fix it?
The %ms notation is a POSIX extension in scanf() compared with the standard C version of scanf()
%msformat is specified by POSIX, not by ISO C.
-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
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
-pedanticoption 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).
Answer: Either drop
-pedantic, or give up
%ms. They don't come together.
AFAIK, there's nothing like
%msformat specifier in ISO C standards. It's added as an extension by POSIX.
The command line argument
-pedantictells GCC to strictly follow the ISO C standards, so it won't accept
%mswith 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