The difference between GCC and g++

Source: Internet
Author: User

Java EE Development of various types of resources download list, the history of the most complete IT resources, personal collection summary.

Many people don't quite understand the difference between GCC and g++.
Both GCC and g++ are a compiler of the GNU (Organization).

Myth One: gcc can only compile C code, g++ can only compile C + + code
Both are possible, but please note:
1. The suffix is. c, and GCC treats it as a C program, and g++ is a C + + program; the suffix is. cpp, both of which are considered C + + programs, note that although C + + is a superset of C, there is a difference between the two requirements for grammar. C + + syntax rules are more rigorous.
2. The compile phase, g++ will call GCC, for C + + code, the two are equivalent, but because the GCC command is not automatic and C + + program use of the library join, so often use g++ to complete the link, for the sake of unification, simply compile/link all use g++, this gives a person an illusion, As if the CPP program can only use g++-like.

Myth Two: gcc does not define __cplusplus macros, and g++
In fact, the macro simply indicates that the compiler will interpret the code in C or C + + syntax, as described above, if the suffix is. C and the GCC compiler is used, the macro is undefined, otherwise it is defined.

Myth Three: Compile only with GCC, links can only use g++
Strictly speaking, this sentence is not wrong, but it confuses the concept, it should be said: The compiler can use gcc/g++, and links can be used g++ or gcc-lstdc++. Because the GCC command does not automatically connect to libraries used by C + + programs, g++ is usually used to complete the join. In the compile phase, however, g++ automatically invokes GCC, which is equivalent.
The difference between GCC and g++
When we compile C + + code, some people use GCC, some people use g++, so all kinds of statements come, such as C code with GCC, and C + + code with g++, or compile with GCC, link with g++, temporarily also do not know which statement is correct, if you encounter the last extern "C", The difference is more, here I want to make a conclusion, after all, the purpose of knowledge is to be more sober, not more confused.

misunderstanding four: extern "C" and gcc/g++ have relations
In fact, it doesn't matter whether GCC or g++, with extern "C", is named for symbol in C, otherwise it is named in C + +. The experiment is as follows:
Me.h:
extern "C" void cppprintf (void);

Me.cpp:
#include
#include "me.h"
using namespace Std;
void cppprintf (void)
{
cout
#include
#include "me.h"
int main (void)
{
Cppprintf ();
return 0;
}

1. Add extern "C" to me.h first, see what is the difference between GCC and g++ naming
[Root@root g++]# g++-S Me.cpp
[Root@root g++]# less ME.S
. GLOBL _Z9CPPPRINTFV//Note the name of this function
. Type cppprintf, @function
[Root@root gcc]# gcc-s Me.cpp
[Root@root gcc]# less ME.S
. GLOBL _Z9CPPPRINTFV//Note the name of this function
. Type cppprintf, @function
Exactly the same.

2. Remove the me.h in the extern "C", see what is the difference between GCC and g++ naming
[Root@root gcc]# gcc-s Me.cpp
[Root@root gcc]# less ME.S
. GLOBL _Z9CPPPRINTFV//Note the name of this function
. Type _Z9CPPPRINTFV, @function
[Root@root g++]# g++-S Me.cpp
[Root@root g++]# less ME.S
. GLOBL _Z9CPPPRINTFV//Note the name of this function
. Type _Z9CPPPRINTFV, @function
Exactly the same.


"Conclusion" can be seen that the extern "C" and the use of gcc/g++ does not relate to the above test also indirectly confirms the previous saying: In the compilation phase, g++ is called GCC.

Reprint statement: This article transfers from http://www.linuxdiyf.com/bbs/thread-109684-1-1.html (Linux Red Union area)

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.