LinuxQuestions.org
Download your favorite Linux distribution at LQ ISO.
Go Back   LinuxQuestions.org > Forums > Linux Forums > Linux - Software
User Name
Password
Linux - Software This forum is for Software issues.
Having a problem installing a new program? Want to know which application is best for the job? Post your question in this forum.

Notices


Reply
  Search this Thread
Old 01-30-2008, 12:04 PM   #1
nano2
Member
 
Registered: May 2007
Posts: 100

Rep: Reputation: 15
Using Gnu C++ to compile c code


Hi ,
I am using gcc4.2.2 on redhat 4.5 to compile c code using the GNU C++ library but it is extremely pedantic very sensitive I need to cast most of my assignments .

Invalid conversion from 'void*' to 'char*'

I have been searing thru the g++ manual for a flag that tells the compiler this is fine , but can't see anything obvious .
Has any one any ideas.
Thanks

Now when using gcc all is fine but I need to use c++ as I have an issue with the application .

The Flags I am using are :
CFLAGS += -Wall -Wno-parentheses -Wno-format -Wno-char-subscripts -DINLINE="static inline" -Wno-deprecated -fno-access-control

CXXFLAGS += -Wno-deprecated -fno-access-control -m64 -Wall
 
Old 01-30-2008, 01:17 PM   #2
Matir
LQ Guru
 
Registered: Nov 2004
Location: San Jose, CA
Distribution: Ubuntu
Posts: 8,507

Rep: Reputation: 128Reputation: 128
Are you using gcc, or g++? There are some differences in your invocations.
 
Old 01-30-2008, 02:10 PM   #3
LinuxManMikeC
Member
 
Registered: Nov 2007
Location: Provo, Utah
Distribution: Debian and Ubuntu
Posts: 74

Rep: Reputation: 15
Firstly, I can think of no valid reason to be compiling C code in a C++ compiler other than you are migrating the code to C++. What is your reason for compiling C code with g++? In fact, if anyone has a good reason, please share.

Secondly, its not pedantic, its different. You are assuming C can just be dropped into a C++ compiler and work. In general that is true, but C++ is not 100% compatible with C. In this case the permissiveness of implicit casting in C was dropped for greater type safety in C++. This can be solved with an explicit cast (and C++ will support the C style cast, though the C++ forms are advisable for new C++ code).

Finally, if you don't want all this "pedantic" trouble, use gcc! Its the tool for the job. If you really need C++ to catch problems in your C code then maybe you should just migrate to C++. Maybe this implicit cast is part of the problem with the code? In which case, this error is exactly what you were looking for.



P.S. And I just noticed this...
Quote:
Originally Posted by nano2 View Post
... to compile c code using the GNU C++ library...
Unless you are using C++ specific headers, it is still essentially the same library as in C, hence, no benefit.
 
Old 01-31-2008, 07:58 AM   #4
nano2
Member
 
Registered: May 2007
Posts: 100

Original Poster
Rep: Reputation: 15
I initially was using gcc to compile the .c files . But I have a mixture of .c files and c++ files and this version of gcc has been given me issues at runtime so decided to build the project( c & c++ files) with the C++ compiler .

So does any one know how the flag so that i can switch g++/c++ compiler to be ansi c compliant - I sure there is a flag but i can't seem to spot it in the man pages i have used -ansi
 
Old 01-31-2008, 08:14 AM   #5
Matir
LQ Guru
 
Registered: Nov 2004
Location: San Jose, CA
Distribution: Ubuntu
Posts: 8,507

Rep: Reputation: 128Reputation: 128
-ansi sets either gcc or g++ to use ANSI standards mode.
 
Old 01-31-2008, 08:31 AM   #6
nano2
Member
 
Registered: May 2007
Posts: 100

Original Poster
Rep: Reputation: 15
Is there way i can disable this as I have it set in CFLAGS=-ansi
But I am still getting problems with enum types - complaing that's it not declared in this scope .. This works fine when compiled with gcc . It is declared but looks like the C++ complier can't see it ...

so is there a switch flag i can turn on so that g++/c++ behaves like gcc ???????
 
Old 01-31-2008, 09:37 AM   #7
Matir
LQ Guru
 
Registered: Nov 2004
Location: San Jose, CA
Distribution: Ubuntu
Posts: 8,507

Rep: Reputation: 128Reputation: 128
You can use 'gcc'. g++ will only compile ANSI C++ code, not ANSI C.
 
Old 01-31-2008, 10:21 AM   #8
nano2
Member
 
Registered: May 2007
Posts: 100

Original Poster
Rep: Reputation: 15
I know that and have compiled the c code with gcc before But because of this issue mixing compilers ... I have decided to compile all the the code with C++ . I sther no swich for g++/c++ to disable ANSI C++ and to use ansi c. I having problems with GCC at runtime so this may be coz of mixing two compiler c++/gcc
 
  


Reply


Thread Tools Search this Thread
Search this Thread:

Advanced Search

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is Off
HTML code is Off



Similar Threads
Thread Thread Starter Forum Replies Last Post
Source code for GNU utils? itz2000 Linux - Newbie 6 11-11-2007 01:43 PM
LXer: Speed your code with the GNU Profiler LXer Syndicated Linux News 0 04-04-2006 09:21 PM
what is GNU/Linux Source Code tivo 5.1 software for? rjwright Linux - Software 2 12-10-2003 01:04 PM
Releasing source code into GNU TexasDex Linux - Software 1 04-16-2003 05:39 PM
NEWB - Learning to code under GNU/Linux bkeating Linux - Newbie 5 10-09-2002 08:06 PM

LinuxQuestions.org > Forums > Linux Forums > Linux - Software

All times are GMT -5. The time now is 07:28 PM.

Main Menu
Advertisement
My LQ
Write for LQ
LinuxQuestions.org is looking for people interested in writing Editorials, Articles, Reviews, and more. If you'd like to contribute content, let us know.
Main Menu
Syndicate
RSS1  Latest Threads
RSS1  LQ News
Twitter: @linuxquestions
Facebook: linuxquestions Google+: linuxquestions
Open Source Consulting | Domain Registration