DEV-C ++ experiment with long long type

xiaoxiao2021-03-06  13

Kingwei 2005.3.10

Experimental environment: DEV-C 4.9.6.0 (GCC / MINGW32), use -wall compile options

#include

int main () {signed long long int v_signed_long_long_int; unsigned long long int v_unsigned_long_long_int; / * PART1: USE% I64d AND% I64u * / / * [-2 ^ 63, 2 ^ 63-1] ==> [-9223372036854775808, 9223372036854775807] * / scanf ("% i64d", & v_signed_long_long_int); Printf ("% i64D / n", v_signed_long_long_int);

/ * [0, 2 ^ 64-1] ==> [0, 18446744073709551615] * / scanf ("% i64u", & v_unsigned_long_long_int); Printf ("% i64u / n", v_unsigned_long_long_int);

/ * Part2: USE% LLD and% llu * / / * [-2 ^ 63, 2 ^ 63-1] ==> [-9223372036854775808, 92233775854775807] * / scanf ("% LLD", & v_signed_long_long_int); printf (" % LLD / N ", v_signed_long_long_int);

/ * [0, 2 ^ 64-1] ==> [0, 18446744073709551615] * / scanf ("% llu", & v_unsigned_long_long_int); Printf ("% llu / n", v_unsigned_long_long_int); return 0;}

This program compiled under DEV-C will have a series of WARNING:

D: / DEV-C Experiment / LetinT_Format.cpp [Warning] in Function `Int Main () ': 14 D: / DEV-C Under the LONG Long Type LONT_FORMAT.CPP [Warning] UNKNOWN Conversion Type Character `i 'in format14 D: / DEV-C LONT_FORMAT.CPP [Warning] Too Many Arguments for Format15 D: / DEV-C under Forement15 D: / DEV-C . CPP [Warning] Unknown Conversion Type Character `i 'in format15 D: / DEV-C About long long type experiment / letint_format.cpp [Warning] Too Many Arguments for Format18 D: / DEV-C Under Long Long Type Experiment / LetinT_Format.cpp [Warning] Unknown Conversion Type Character `i 'in format18 D: / DEV-C About long long type experiment / letint_format.cpp [Warning] Too Many Arguments for Format19 D: / DEV-C Long long type experiment / letint_format.cpp [Warning] Unknown Conversion Type Character `i 'in format19 d: / dev-c LONT_FORMAT.CPP [Warning] Too Many Arguments for Format can be seen, Warning is due to the use of formats% I in Part 1, resulting. PART2 is all normally, and the compiler does not give any warning information.

But - see the test results:

----- Test Case # 1: Down -----

-92233720368547758080-92233720368547758080

OUTPUT:

-9223372036854775808000

----- Test Case # 2: Upload -----

92233720368547758071844674407370955161592233720368547758718446744073709551615

OUTPUT:

922337203685477580718446744073709551615-14294967295

----- Test Case # 3: Upperflow -----

-9223372036854775809-1-9223372036854775809-1

OUTPUT:

922337203685477580718446744073709551615-14294967295

----- Test Case # 4: overflow -----

922337203685477580818446744073709551616922337203685477580818446744073709551616

OUTPUT:

-9223372036854775808000

As a result, in contrast, Part1 was completely normal, and Part 2 has a problem. Why? I am telling us:

"% LLD" and "% llu" are the formatters of GCC / G for long long int type (64 bits) in Linux. The "% i64D" and "% i64u" are formatted by Microsoft VC reservoirs for inputting output __int64 types.

The problem is: DEV-C compiler is MINGW32, MINGW32 is one of the X86-Win32 GCC sub-projects, the compiler core or the GCC under Linux.

The function parameter type check is checked in the compile stage, the GCC compiler checks this code, obviously it does not recognize "% i64D", so gives a warning "Unknown Conversion Type Character` I 'in format ", it does not think This is a format specifier. Next, the GCC discovered that there was no legitimate specifere in the entire format string, but passed to the PrintF / Scanf in addition to the format string, and data parameters, so it gave the second warning "Too Many Arguments for Format".

For "% LLD" and "% llu", GCC is underway. The tragedy buried this.

MINGW32 uses GCC rules to check syntax during compilation, but uses the Microsoft library when connecting and running. The Printf and Scanf functions in this library certainly do not know "% LLD" and "% llu" under Linux GCC, "% i64D" and "% i64u", it is willing to accept.

- The result appeared above.

转载请注明原文地址:https://www.9cbs.com/read-48559.html

New Post(0)