473,320 Members | 2,109 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,320 software developers and data experts.

Why would someone use c++ compiler on a C code?


Would it suppress errors?

Is he trying to hide errors in his code?
Apr 8 '08 #1
14 1839
On Apr 7, 9:56 pm, 2005 <FW3...@sbcglobal.netwrote:
Would it suppress errors?

Is he trying to hide errors in his code?
He is using g++ on a *.c code!

Also what is so different between gcc & cc compiler - any advantages?
Apr 8 '08 #2
2005 wrote:
Would it suppress errors?

Is he trying to hide errors in his code?
Probably the reverse, C++ and its compilers are more pedantic about a
number of issues, particularly type safety.

Do bear in ming there are sometimes obscure semantic differences between
the two languages, so you would be ill advised to try this at home
unless you are aware of the risks.

--
Ian Collins.
Apr 8 '08 #3
On Apr 7, 10:01 pm, Ian Collins <ian-n...@hotmail.comwrote:
2005 wrote:
Would it suppress errors?
Is he trying to hide errors in his code?

Probably the reverse, C++ and its compilers are more pedantic about a
number of issues, particularly type safety.

Do bear in ming there are sometimes obscure semantic differences between
the two languages, so you would be ill advised to try this at home
unless you are aware of the risks.

--
Ian Collins.
I tried this code on "cc -c" - it gave numerous errors
But non when I did g++ on a C code

Is this a good practice to compile a C code with g++ compiler.
Apr 8 '08 #4
2005 wrote:
On Apr 7, 10:01 pm, Ian Collins <ian-n...@hotmail.comwrote:
>2005 wrote:
>>Would it suppress errors?
Is he trying to hide errors in his code?
Probably the reverse, C++ and its compilers are more pedantic about a
number of issues, particularly type safety.

Do bear in ming there are sometimes obscure semantic differences between
the two languages, so you would be ill advised to try this at home
unless you are aware of the risks.
*Please* don't quote signatures.
>
I tried this code on "cc -c" - it gave numerous errors
But non when I did g++ on a C code
Then the code is more than likely C like C++, not C.
Is this a good practice to compile a C code with g++ compiler.
Not unless you have a specific reason for doing so.

--
Ian Collins.
Apr 8 '08 #5
In article
<a4**********************************@q27g2000prf. googlegroups.com>,
2005 <FW****@sbcglobal.netwrote:
Would it suppress errors?

Is he trying to hide errors in his code?
A C++ compiler *IS*, by definition, a C compiler. PLUS some stuff. And
generally, it's even pickier than its "plain C" counterpart. So no, it's
not likely to suppress errors. If anything, it's more likely to complain
even MORE about errors than a "plain" C compiler would.

In general, unless you're trying to compile C++ code (in which case, a
"plain C" compiler just can't cope) it really doesn't much matter if you
use a "plain" C compiler, or a C++ compiler on a straight C source.

As far as GCC/g++ versus CC, GCC is the "Gnu" version of CC. Not
necessarily any better or worse, just a different "flavor". They both
end up doing the same thing, although they may accomplish it in
different ways. As far as which is better, you'd have to go deep into
the guts of both the compiler, and the code it produces, to make any
meaningful call about that. As I said, they both do the same thing -
Grind up C (or C++) source code and spit out ready-to-link binary files.
One might spit out "better" binary files than the other for some kinds
of code, while the other one spits out better binary files for another
type of code. There's just *WAY* too many variables to flatly state that
one is "better than" the other.

The most obvious advantages of the "Gnu" version are that it's (1) Free,
and (2) Open Source. Average folks aren't going to care all that much
about the "Open Source" part, but the "Free" concept makes it REALLY
attractive...

--
Don Bruder - da****@sonic.net - If your "From:" address isn't on my whitelist,
or the subject of the message doesn't contain the exact text "PopperAndShadow"
somewhere, any message sent to this address will go in the garbage without my
ever knowing it arrived. Sorry... <http://www.sonic.net/~dakiddfor more info
Apr 8 '08 #6
2005 wrote:
Would it suppress errors?

Is he trying to hide errors in his code?
Please repeat your question in the body of your message; don't just ask
it in the subject.

Others have suggested some solutions. The FAQ question 20.27 "Is C++ a
superset of C? What are the differences between C and C++? Can I use a
C++ compiler to compile C code?" will probably help you as well. The FAQ
also links to a statement on the subject from Bjarne Stroustrup, the
creator of C++. You can find the FAQ at http://c-faq.com/

Philip
Apr 8 '08 #7
Richard Heathfield wrote:
>
/* Please convert this program to C++ using the
* following rules:
I tried to compile it as C first at got:

"/tmp/x.c", line 34: warning: no explicit type given
"/tmp/x.c", line 37: syntax error before or at: )
"/tmp/x.c", line 81: warning: implicit function declaration: toupper
"/tmp/x.c", line 86: warning: implicit function declaration: tolower
>
(Incidentally, this program also demonstrates that C99 isn't a superset of
C90.)
So after renaming identifiers, a C++ compiler gave similar errors:

"/tmp/x.c", line 33: Error: Cannot use const char[82] to initialize
char[81].
"/tmp/x.c", line 37: Error: Unexpected ")" -- Check for matching
parenthesis.
"/tmp/x.c", line 81: Error: The function "toupper" must have a prototype.
"/tmp/x.c", line 86: Error: The function "tolower" must have a prototype.

So what does this prove? C++ is closer to C99? C90 isn't C or C++?

--
Ian Collins.
Apr 8 '08 #8
Ian Collins said:
Richard Heathfield wrote:
>>
/* Please convert this program to C++ using the
* following rules:

I tried to compile it as C first at got:

"/tmp/x.c", line 34: warning: no explicit type given
"/tmp/x.c", line 37: syntax error before or at: )
A copyo, perhaps? It compiles just fine here, under the strictest set of
flags I can summon up.
"/tmp/x.c", line 81: warning: implicit function declaration: toupper
"/tmp/x.c", line 86: warning: implicit function declaration: tolower
Neither of these diagnostic messages is mandatory: implicit int is legal in
C...
>>
(Incidentally, this program also demonstrates that C99 isn't a superset
of C90.)
....except, of course, when it isn't.
So what does this prove? C++ is closer to C99? C90 isn't C or C++?
It demonstrates what we already know - i.e. that C++ compilers can't
compile C programs. It makes this very obvious. What is less obvious is
that C++ compilers can't compile C programs *even when the program is
valid C++*. That's because, if a C++ compiler is compiling it, it is by
definition a C++ program - i.e. a program that is translated according to
C++ rules. It might *also*, at another time or place, be a C program (i.e.
a program that can be translated correctly according to C rules) - but
when the C++ compiler has its teeth into it, it is not reasonable to call
it anything other than a C++ program.

--
Richard Heathfield <http://www.cpax.org.uk>
Email: -http://www. +rjh@
Google users: <http://www.cpax.org.uk/prg/writings/googly.php>
"Usenet is a strange place" - dmr 29 July 1999
Apr 8 '08 #9
Richard Heathfield wrote:
Ian Collins said:
>Richard Heathfield wrote:
>>/* Please convert this program to C++ using the
* following rules:
I tried to compile it as C first at got:

"/tmp/x.c", line 34: warning: no explicit type given
"/tmp/x.c", line 37: syntax error before or at: )

A copyo, perhaps? It compiles just fine here, under the strictest set of
flags I can summon up.
>"/tmp/x.c", line 81: warning: implicit function declaration: toupper
"/tmp/x.c", line 86: warning: implicit function declaration: tolower

Neither of these diagnostic messages is mandatory: implicit int is legal in
C...
Read them again "implicit function declaration". Your forgot <ctype.h>

Implicit int is illegal in both C99 (C) and C++.
>>(Incidentally, this program also demonstrates that C99 isn't a superset
of C90.)

....except, of course, when it isn't.
>So what does this prove? C++ is closer to C99? C90 isn't C or C++?

It demonstrates what we already know - i.e. that C++ compilers can't
compile C programs.
More topically it shows a C99 compiler can't compile a C90 program.

--
Ian Collins.
Apr 8 '08 #10
Ian Collins said:
Richard Heathfield wrote:
>Ian Collins said:
<snip>
>>
>>"/tmp/x.c", line 81: warning: implicit function declaration: toupper
"/tmp/x.c", line 86: warning: implicit function declaration: tolower

Neither of these diagnostic messages is mandatory: implicit int is legal
in C...
Read them again "implicit function declaration". Your forgot <ctype.h>
No, I didn't. I just mis-typed "implicit function declaration". :-)
Implicit function declaration is, of course, legal in C90 (C).
Implicit int is illegal in both C99 (C) and C++.
Right.
>>>(Incidentally, this program also demonstrates that C99 isn't a
superset of C90.)

....except, of course, when it isn't.
>>So what does this prove? C++ is closer to C99? C90 isn't C or C++?

It demonstrates what we already know - i.e. that C++ compilers can't
compile C programs.

More topically it shows a C99 compiler can't compile a C90 program.
Well, yes - but I think we knew that already. :-) More generally, it
illustrates the potentially interesting point that you can't necessarily
tell what a program will do, just by looking at it.

--
Richard Heathfield <http://www.cpax.org.uk>
Email: -http://www. +rjh@
Google users: <http://www.cpax.org.uk/prg/writings/googly.php>
"Usenet is a strange place" - dmr 29 July 1999
Apr 8 '08 #11
Richard Heathfield wrote:
Ian Collins said:
>Richard Heathfield wrote:
>>Ian Collins said:
<snip>
>>>"/tmp/x.c", line 81: warning: implicit function declaration: toupper
"/tmp/x.c", line 86: warning: implicit function declaration: tolower
Neither of these diagnostic messages is mandatory: implicit int is legal
in C...
Read them again "implicit function declaration". Your forgot <ctype.h>

No, I didn't. I just mis-typed "implicit function declaration". :-)
Implicit function declaration is, of course, legal in C90 (C).
Now where did I leave my Tardis?

--
Ian Collins.
Apr 8 '08 #12

MMcL"Martin Ambuhl" <ma*****@earthlink.netwrote in message
MMcLnews:66*************@mid.individual.net...
>Don Bruder wrote:
>A C++ compiler *IS*, by definition, a C compiler. PLUS some
stuff.
The above is complete nonsense. It is unbelievable that someone
who knows so little can write so much with a presumed air of
authority. Until we see evidence that Don Bruder has learned
something, it is safer to ignore him. For example.
MMcLManners, manners, manners. Don Bruder is relatively new to
MMcLthe group and what he said is an easy mistake for a
MMcLrelatively well-informed person to make.

Only if your definition of "relatively well-informed" is so vague as
to be useless; someone who thinks C++ is a proper superset of C,
modulo keywords, isn't very well-informed about either language.

And calling it complete nonsense isn't rude; neither is pointing out
that people who write complete nonsense to this group are frequently
corrected but otherwise ignored.

Charlton
--
Free games and programming goodies.
http://www.personal.leeds.ac.uk/~bgy1mm
--
Charlton Wilbur
cw*****@chromatico.net
Apr 8 '08 #13

"Kelsey Bjarnason" <kb********@gmail.comwrote in message
news:sr************@spanky.localhost.net...
[snips]

On Mon, 07 Apr 2008 22:41:49 -0700, Don Bruder wrote:
>A C++ compiler *IS*, by definition, a C compiler.


#include <stdlib.h>

int main(void)
{
char *s = malloc(100);
if ( s ) free( s );
return 0;
}

gcc -Wall -ansi -pedantic test.c compiles clean. Note the use of the
proper C idiom of *not* casting the return of malloc, which is both
intentional and correct.

Actually that idiom was retained, reluctantly, to avoid breaking reams of
legacy code, as committee members have informed us in previous posts to this
ng.

One effect is that if used in new code, the program will no longer compile
under C++.

--
Free games and programming goodies.
http://www.personal.leeds.ac.uk/~bgy1mm

Apr 8 '08 #14
dj******@csclub.uwaterloo.ca.invalid writes:
<OT>
In article <86**********************************@1g2000prf.go oglegroups.com>,
2005 <FW****@sbcglobal.netwrote:
>>On Apr 7, 9:56 pm, 2005 <FW3...@sbcglobal.netwrote:

[Subject: Why would someone use c++ compiler on a C code?]
<snip>
>>He is using g++ on a *.c code!

g++ will act as a C compiler when given the file 'foo.c', unless you
specifically ask it to do otherwise.
<snip>
gcc will always give you the GNU C compiler, unless the system was
deliberately set up to be confusing and/or broken.
gcc will return the favour -- i.e. it will compile a C++ program if
the source is called, for example, x.cc.

I don't think you meant to imply otherwise, but some people might read
what you said as suggesting gcc is always a C compiler. I find it
helps always to use -std=c89 or -std=c99 etc. That way you get told
if you feed it a file that it takes to be in another language.
</OT>
--
Ben.
Apr 8 '08 #15

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

42
by: Mike P. | last post by:
Hello I come from the world of C++ programming, and I'm used to writing programs that are actually executed by the CPU, and that run with some semblance of performance. I have taken the time to...
2
by: marco | last post by:
the problem: I use a typedef inside a class template, than I use this type (dim_v<N1>::Type) to define the argument of a template function f but when I call this function from main, the compiler...
20
by: nicolas.riesch | last post by:
I try to understand strict aliasing rules that are in the C Standard. As gcc applies these rules by default, I just want to be sure to understand fully this issue. For questions (1), (2) and...
12
by: Andrew Ducker | last post by:
And no, this isn't a complaint about break - I'm very happy to make things explicit. However, why isn't the format something like: switch(myVariable) { case 1: { //Do Something
5
by: jignasuk | last post by:
Hello, 1 unsigned char ar = "AB"; 2 unsigned int i = 0; 3 i = *(unsigned int *)ar; How does it convert to unsigned int from unsigned char()? After executing this three line I am getting...
7
by: CMirandaman | last post by:
I have another newbie question I could use some help with. I ran across this code in one of the MS training guides: public class NullTokenVisitor {...} public class Application { public...
6
by: thomas.luce | last post by:
Okay, I have been programming for a long time, and am getting back into C after about a 4 year break from it. Below is some code that won't compile for the life of me, and it is driving me crazy!...
8
by: Joshua Moore | last post by:
/* Hi, I was hoping someone could help me with this problem. I did my work and worked my way through the usual compiler messages, but I have run against some problem I can't identify. The compiler...
30
by: Anarki | last post by:
The following is the program i am trying to compile //restrict.c #include <stdio.h> int main() { char arr = "Qualifiers" char * restrict p = arr; int i = 0; for(; i < 10; ++i)
0
by: DolphinDB | last post by:
Tired of spending countless mintues downsampling your data? Look no further! In this article, you’ll learn how to efficiently downsample 6.48 billion high-frequency records to 61 million...
0
by: ryjfgjl | last post by:
ExcelToDatabase: batch import excel into database automatically...
0
isladogs
by: isladogs | last post by:
The next Access Europe meeting will be on Wednesday 6 Mar 2024 starting at 18:00 UK time (6PM UTC) and finishing at about 19:15 (7.15PM). In this month's session, we are pleased to welcome back...
0
by: ArrayDB | last post by:
The error message I've encountered is; ERROR:root:Error generating model response: exception: access violation writing 0x0000000000005140, which seems to be indicative of an access violation...
1
by: PapaRatzi | last post by:
Hello, I am teaching myself MS Access forms design and Visual Basic. I've created a table to capture a list of Top 30 singles and forms to capture new entries. The final step is a form (unbound)...
1
by: Defcon1945 | last post by:
I'm trying to learn Python using Pycharm but import shutil doesn't work
1
by: Shællîpôpï 09 | last post by:
If u are using a keypad phone, how do u turn on JavaScript, to access features like WhatsApp, Facebook, Instagram....
0
by: af34tf | last post by:
Hi Guys, I have a domain whose name is BytesLimited.com, and I want to sell it. Does anyone know about platforms that allow me to list my domain in auction for free. Thank you
0
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 3 Apr 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome former...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.