Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Difference between -Wconversion between gcc and g++ [duplicate]

Tags:

c++

c

gcc

g++

Possible Duplicate:
Can I make GCC warn on passing too-wide types to functions?

Consider the following test program:

static void func(int a)
{
}

int main()
{
    unsigned int b = 42;

    func(b);

    return 0;
}

Compiling it with gcc:

lol@mac:~/projects$ gcc -Wconversion testit.c
testit.c: In function âmainâ:
testit.c:11: warning: passing argument 1 of âfuncâ as signed due to prototype
lol@mac:~/projects$

But, in g++ there is no warning!:

lol@mac:~/projects$ g++ -Wconversion testit.c
lol@mac:~/projects$

What is the reason for this and is there any way to get the same warning when compiling C++ code?

like image 256
user61768 Avatar asked Feb 03 '09 03:02

user61768


People also ask

Is GCC and G ++ same?

DIFFERENCE BETWEEN g++ & gccg++ is used to compile C++ program. gcc is used to compile C program.

Which is better GCC or G ++?

Difference between gcc and g++ Both are the compilers in Linux to compile and run C and C++ programs. Initially gcc was the GNU C Compiler but now a day's GCC (GNU Compiler Collections) provides many compilers, two are: gcc and g++. gcc is used to compile C program while g++ is used to compile C++ program.

Do I need both GCC and G ++?

For c++ you should use g++. It's the same compiler (e.g. the GNU compiler collection). GCC or G++ just choose a different front-end with different default options.

What is G in GCC?

GCC stands for “GNU Compiler Collection”. GCC is an integrated distribution of compilers for several major programming languages. These languages currently include C, C++, Objective-C, Objective-C++, Fortran, Ada, D, and Go.


1 Answers

From the documentation for -Wconversion:

Warnings about conversions between signed and unsigned integers are disabled by default in C++ unless -Wsign-conversion is explicitly enabled.

Seems that you'll need a sufficiently new version of GCC, too. I have version 4.0.1, and it doesn't recognize -Wsign-conversion.

like image 195
Rob Kennedy Avatar answered Sep 30 '22 16:09

Rob Kennedy