+void suite_six()
+{
+ char const * string = "-0xz\n";
+ CHECK_EQUAL( string[4], '\n' );
+ {
+ // reading -0x, x
+ unsigned char i = 1;
+ int n = -1;
+ /* Most existing libraries disagree with this test driver, so a little
+ explanation of why PDCLib chose the implementation it did might be
+ necessary. All references are from ISO/IEC 9899:1999 "Programming
+ languages - C". Wording critical to the explanation is in UPPERCASE.
+ 6.4.4.1 Integer constants - states that '0' is a valid (hexa)decimal
+ constant, whereas '0x' IS NOT.
+ 7.19.6.2 The fscanf function - states...
+ ...in paragraph 9 that "an INPUT ITEM is defined as the longest
+ sequence of input characters [...] which is, OR IS A PREFIX OF,
+ a matching input sequence".
+ ...in paragraph 10 that "if the INPUT ITEM is not a matching
+ sequence, the execution of THE DIRECTIVE FAILS; this condition
+ is a matching failure".
+ ...in footnote 242) that "fscanf pushes back AT MOST ONE input
+ character onto the input stream."
+ ...in paragraph 12 that either of the conversion specifiers d, i,
+ o, u, or x "matches an [...] integer whose format is the same as
+ expected for THE SUBJECT SEQUENCE of the [strtol|strtoul]
+ function".
+ 7.20.1.4 The strtol, strtoll, strtoul, and strtoull functions - states
+ in paragraph 3 that "the EXPECTED FORM OF THE SUBJECT SEQUENCE is
+ that of an integer constant AS DESCRIBED IN 6.4.4.1".
+ These parts of the standard result in the following reasoning:
+ - The longest sequence of input characters which is a prefix of a
+ matching input sequence is "-0x" (negative sign, hexadecimal-prefix).
+ The 'z' is the first character remaining unread as "-0xz" is not a
+ (prefix of a) matching input sequence. This is according to 7.19.6.2
+ paragraph 9.
+ - "0x", without a valid hexadecimal digit following it, is not a valid
+ integer constant according to 6.4.4.1.
+ - "0x" is thus also not of the expected form for a strto[u]l subject
+ sequence according to 7.20.1.4 paragraph 3. (strto[u]l() would parse
+ it as zero, but leave the "x" in the final string, i.e. outside the
+ subject sequence.)
+ - "0x" is therefore also not a matching sequence to the i or x
+ conversion specifier according to 7.19.6.2 paragraph 12.
+ - The conversion should therefore result in a matching failure
+ according to 7.19.6.2 paragraph 10.
+ */
+ CHECK_EQUAL( sscanf( string, "%hhx%n", &i, &n ), 0 );
+ CHECK_EQUAL( i, 1 );
+ CHECK_EQUAL( n, -1 );
+ }
+ {
+ // reading -0x, x
+ unsigned short i = 1;
+ int n = -1;
+ CHECK_EQUAL( sscanf( string, "%hx%n", &i, &n ), 0 );
+ CHECK_EQUAL( i, 1 );
+ CHECK_EQUAL( n, -1 );
+ }
+ {
+ // reading -0x, x
+ unsigned int i = 1;
+ int n = -1;
+ CHECK_EQUAL( sscanf( string, "%x%n", &i, &n ), 0 );
+ CHECK_EQUAL( i, 1 );
+ CHECK_EQUAL( n, -1 );
+ }
+}
+