Use of the optional m modifier for scanf

The scanf manpage specifies an optional modifier for string inputs:

image

This does not seem to be part of every documentation (e. g. Microsofts C runtime documentation). Are we allowed to use this modifier, since we are using glibc?

Good question.

The m character is a POSIX extension. The plain C definition of fscanf can be found here: N1570 April 12, 2011 ISO/IEC 9899:201x. It does not describe that modifier, so it is undefined behavior.

The POSIX standard is what most existing unixoid OSs (notably Linux and Mac OS) try to conform to. The definition of fscanf for POSIX includes the m modifier, it can be found here: N1570 April 12, 2011 ISO/IEC 9899:201x. So basically, your C code can expect to work fine as long as the platform you are building respects that standard.

Windows is not a POSIX OS, so Microsoft’s manpages do not mention that character since it is not supported on Windows.

Since the VM and the test servers run a fairly standard version of Linux, and since we guarantee that any code that works in the VM should work on our servers, you can use it.

2 Likes