OJ the difference between g++ and C + + in the language options in the submission topic

Source: Internet
Author: User

Fundamental differences:

Hduoj, g++ use is mingw,c++ with Msvc;mingw I/O speed is relatively slow, this is also some people with g++ timeout, and C + + AC Reason


Difference One:

1, the output double type, if the use of g++ submission, scanf adopt%lf,prinf%f, otherwise will error 2, use gcc/g++ Reminder: for 64-bit integers, long long int and __int64 are both supported and equivalent. But only support scanf when reading and writing ("%i64d", ...) and printf ("%i64d", ...). "%LLD" is not supported because the C99 standard is not supported by the Msvcrt.dll dynamic link libraries used by GCC and g++ under MinGW. According to the ISO C + + standard, the return value of the main function must be int in g++, otherwise it will cause compile Error ( Compilation error 3, G++/GCC use scanf, printf note reference <stdio.h>, reference only <iostream> not recognized


Difference Two:

<span style= "FONT-SIZE:18PX;" >g++? First of all, correct a concept, C + + is a computer programming language, g++ is not a language, is a compiler to compile C + + program commands. So what's the difference between them? In the language options in the submission topic, g++ and C + + both represent the way to compile. To be precise, choosing C + + means that you will be using the most standard compilation method, which is the ANSI C + + compilation. If you're using g++, it means you'll use the most mundane compilers in the GNU project (in fact, the Code::Blocks's own compiler that we're familiar with, which is typically the MinGW gcc in the Windows environment, In Linux, GCC and the former are basically a thing) to compile. Similar to the choice of C and GCC, the former is the standard C compiler compiled, the latter is also using GCC to compile. Compiler differences-compiler optimization of course, many times we have code in C + + submitted through, but g++ failed? It is well known that different compilers make some different optimizations to the code. Give me one of the simplest examples. For a single statement (note that it is a single statement, not the kind of front + + and after + + that is included in the statement):</span>




View sourceprint?1.a:a++;2.b: ++a;


Generally speaking, we all know that the final result of these two statements is the same, that is, a self-increase of 1. However, the gap between the two is still there. If you understand it from the perspective of standard C. a++ This statement is equivalent to


View Sourceprint?1.a:a = a + 1


That is, I am calling first, then self-increasing. During the call, a new data address is requested to hold the temporary variable a ', then a ' is added 1, then a ' is assigned to a. But ++a this statement does not need to be so troublesome. Because he is the first self-increase, after the call, that is, to save the application of new address of Kung Fu. So theoretically, the time consumption is different, if you are using the standard C compilation method, you can find this difference. After all, the time it takes to apply for temporary memory is much longer than making a change to the known memory data. But the compiler's optimization is reflected in the same results, but time-consuming differences. If you use GCC to compile, you will find that there is basically no difference between the first + + and the Post + +. This is the tip of the iceberg in compiler optimizations. There are, in fact, many areas of optimization. Why did g++ submit WA? All right, come back to reality. I was doing POJ 3122 this problem yesterday, once again met G++wa;c++ac embarrassing situation. Why is it? In fact, this is also part of the compiler optimization, which is the accuracy of the default. As is known to all, a long long type, as a data type that is recognized as a basic data type in c/c++11, has a different type identifier in different environments. That's the%LLD and%i64d we talked about. Similarly, a double type is also an interesting type. The double type is, in fact, precisely the two-precision type, his memory length is generally more than the float type (single-precision) more than one times, sometimes very early in the standard is the double is called long float. So there is the reason why the float type is used with%f,double%lf. But because now is not the kind of memory in the past a few megabytes, more open a double will be super memory age, so double and float in GCC is automatically optimized. When reading data with scanf, the%LF is used in order to distinguish it from float. When writing data in printf, because in essence, double and float are the same type, but memory consumption is different, their identifiers are%f, note that this differs from standard C, here are%f. Of course for another special type long double although not commonly used, but the compiler is still supported, here is an episode, in theory, a long double should be twice times the double (similar to a long long and int relationship, because long and int is actually a thing). But in fact, long double is very strange is a 10-byte monster, he has two free bytes, how the change will not change. The input and output identifiers are%lf, uppercase L. But there's a problem here, why do I use%f in the local area WA, on the OJ with the%f AC? Because if we use the Code::Blocks IDE under Windows, the compiler is MinGW this thing. In fact, in order to try to keep GCC cross-platform, MinGW in some places is directly using msvc things, and the biggest impact on us is the problem of this identifier. Simply put, if you are going to test in a native, then it is best to use that identifier system of standard C; If you want to commit the code, change it to the GCC identifier system. Of course, there is a simpler way, is directly with the input and output stream in the control input and output, it is more convenient, and cross-platform performance is better, there is no such error because of identifiers.




Make a list of what it looks like:


Double F; G++ submits the most secure method for submitting native GCC tests for C + + input scanf ("%lf", &f), scanf ("%lf", &f), scanf ("%lf", &f), CIN >> F; output printf ("%f ", f);p rintf ("%lf ", f);p rintf ("%lf ", f); cout << F;


It is probably so much, I hope you avoid this kind of mistake.



OJ the difference between g++ and C + + in the language options in the submission topic

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.