 |
C++Talk.NET C++ language newsgroups
|
| View previous topic :: View next topic |
| Author |
Message |
Ken Applequist Guest
|
Posted: Wed Sep 15, 2004 11:36 pm Post subject: Will C pgm compile on C++ compiler? |
|
|
I had C programming in school years ago and would like to play with it
again. When I go online I only seem to be able to find C++ compilers. I know
that C++ is object oriented, whereas C is not. I can get a good price on
Visual C++ 6.0. Is there a way to run native C programs on a C++ compiler?
Thanks,
Ken
[ See http://www.gotw.ca/resources/clcm.htm for info about ]
[ comp.lang.c++.moderated. First time posters: Do this! ]
|
|
| Back to top |
|
 |
Tabrez Iqbal Guest
|
Posted: Thu Sep 16, 2004 11:09 am Post subject: Re: Will C pgm compile on C++ compiler? |
|
|
"Ken Applequist" <apple07840 (AT) yahoo (DOT) com> wrote
| Quote: | I had C programming in school years ago and would like to play with it
again. When I go online I only seem to be able to find C++ compilers. I know
that C++ is object oriented, whereas C is not. I can get a good price on
Visual C++ 6.0. Is there a way to run native C programs on a C++ compiler?
Thanks,
Ken
|
most of the C programs could be easily compiled using a C++ compiler
unless you are using one of the recent additions to the language
standard - C99("long long" etc). But if you write your C programs
against the older standard of C you are safe, as long as you make sure
to follow the "good" practices(for eg. in first versions of C,
prototyping the functions before use was optional, but its mandatory
in C++).
tabrez
[ See http://www.gotw.ca/resources/clcm.htm for info about ]
[ comp.lang.c++.moderated. First time posters: Do this! ]
|
|
| Back to top |
|
 |
Yevgen Muntyan Guest
|
Posted: Thu Sep 16, 2004 11:15 am Post subject: Re: Will C pgm compile on C++ compiler? |
|
|
Ken Applequist wrote:
| Quote: | I had C programming in school years ago and would like to play with it
again. When I go online I only seem to be able to find C++ compilers.
|
Try http://www.bloodshed.net/devcpp.html
Yevgen
[ See http://www.gotw.ca/resources/clcm.htm for info about ]
[ comp.lang.c++.moderated. First time posters: Do this! ]
|
|
| Back to top |
|
 |
Jack Klein Guest
|
Posted: Thu Sep 16, 2004 11:18 am Post subject: Re: Will C pgm compile on C++ compiler? |
|
|
On 15 Sep 2004 19:36:56 -0400, "Ken Applequist" <apple07840 (AT) yahoo (DOT) com>
wrote in comp.lang.c++.moderated:
| Quote: | I had C programming in school years ago and would like to play with it
again. When I go online I only seem to be able to find C++ compilers. I know
that C++ is object oriented, whereas C is not. I can get a good price on
Visual C++ 6.0. Is there a way to run native C programs on a C++ compiler?
Thanks,
Ken
|
Every C++ compiler that I know of, and certainly every major
commercial or open source C++ compiler, also compiles C. They either
provide a separate compiler in the package, or compile either language
with the same compiler.
In Visual C++, just give your source files names ending in ".c", and
they will be compiled as C automatically.
While Visual C++ 6.0 is badly outdated for standard C++ conformance,
it is actually quite at C90/95 standard conformance.
But if you really want to be prepared to move to C++ as well, Visual
C++ is not that good a choice. I understand that Visual C++ 7.1 is
much better in standard C++, and the Visual Studio 2005 Express Beta,
which you can download for free from Microsoft's web site has been
good with what I have done with it so far.
--
Jack Klein
Home: http://JK-Technology.Com
FAQs for
comp.lang.c http://www.eskimo.com/~scs/C-faq/top.html
comp.lang.c++ http://www.parashift.com/c++-faq-lite/
alt.comp.lang.learn.c-c++
http://www.contrib.andrew.cmu.edu/~ajo/docs/FAQ-acllc.html
[ See http://www.gotw.ca/resources/clcm.htm for info about ]
[ comp.lang.c++.moderated. First time posters: Do this! ]
|
|
| Back to top |
|
 |
Nicolas Pavlidis Guest
|
Posted: Fri Sep 17, 2004 1:59 am Post subject: Re: Will C pgm compile on C++ compiler? |
|
|
"Ken Applequist" <apple07840 (AT) yahoo (DOT) com> writes:
| Quote: | I had C programming in school years ago and would like to play with it
again. When I go online I only seem to be able to find C++ compilers. I know
that C++ is object oriented, whereas C is not. I can get a good price on
Visual C++ 6.0. Is there a way to run native C programs on a C++
compiler?
|
It is called C ++, you understand , no sorry.
It works but you will have to change the headers, here is an example:
In C you include stdio.h
In C++ you include
cstdio
or stdlib.h has been moved to cstdlib
But if you wanna play learn C++, there is much more to play with it :-)
Kind regards,
Nicolas
--
| Quote: | Nicolas Pavlidis | Elvis Presly: | |__ |
Student of SE & KM | "Into the goto" | |__| |
[email]pavnic (AT) sbox (DOT) tugraz.at[/email] | ICQ #320057056 | |
-------------------University of Technology, Graz----------------|
|
[ See http://www.gotw.ca/resources/clcm.htm for info about ]
[ comp.lang.c++.moderated. First time posters: Do this! ]
|
|
| Back to top |
|
 |
Michiel Salters Guest
|
Posted: Fri Sep 17, 2004 2:12 am Post subject: Re: Will C pgm compile on C++ compiler? |
|
|
"Ken Applequist" <apple07840 (AT) yahoo (DOT) com> wrote
| Quote: | I had C programming in school years ago and would like to play with it
again. When I go online I only seem to be able to find C++ compilers. I know
that C++ is object oriented, whereas C is not. I can get a good price on
Visual C++ 6.0. Is there a way to run native C programs on a C++ compiler?
|
C++ is pretty much a superset of good C, so good programs should continue
to run. Some C programs fail for trivial reasons, e.g. using "class"
which then became a keyword.
However, there are enough C compilers around. E.g. the VC++6 you
mentioned is not a very good C++ compiler nowadays (it's 3 versions
behind) but it also has a C compiler (despite the C++ name). That
C compiler is less obsolete, as C didn't change much since 1990.
VC++ switches automatically when compiling .c or .cpp files.
GCC is also available, for free even. It too can compile C.
Regards,
Michiel Salters
[ See http://www.gotw.ca/resources/clcm.htm for info about ]
[ comp.lang.c++.moderated. First time posters: Do this! ]
|
|
| Back to top |
|
 |
Francis Glassborow Guest
|
Posted: Fri Sep 17, 2004 2:23 am Post subject: Re: Will C pgm compile on C++ compiler? |
|
|
In article <42cd213e.0409152309.4a268bcb (AT) posting (DOT) google.com>, Tabrez
Iqbal <tabrez19_i (AT) rediffmail (DOT) com> writes
| Quote: | most of the C programs could be easily compiled using a C++ compiler
unless you are using one of the recent additions to the language
standard - C99("long long" etc). But if you write your C programs
against the older standard of C you are safe, as long as you make sure
to follow the "good" practices(for eg. in first versions of C,
prototyping the functions before use was optional, but its mandatory
in C++).
As well as understand all the incompatibilities that can cause silent |
change to your program:
int main(){
int i = 1;
if(sizeof(int) > 1) i /= (sizeof('a') - 1);
else i = 0;
return 0
}
Is fine as C and almost always contains a divide by zero error in C++
(the exceptions being implementations where sizeof(int) is one.)
--
Francis Glassborow ACCU
Author of 'You Can Do It!' see http://www.spellen.org/youcandoit
For project ideas and contributions: http://www.spellen.org/youcandoit/projects
[ See http://www.gotw.ca/resources/clcm.htm for info about ]
[ comp.lang.c++.moderated. First time posters: Do this! ]
|
|
| Back to top |
|
 |
dietmar_kuehl@yahoo.com Guest
|
Posted: Fri Sep 17, 2004 10:59 am Post subject: Re: Will C pgm compile on C++ compiler? |
|
|
Ken Applequist wrote:
| Quote: | I had C programming in school years ago and would like to play with
it
again. When I go online I only seem to be able to find C++ compilers.
I know
that C++ is object oriented, whereas C is not. I can get a good price
on
Visual C++ 6.0. Is there a way to run native C programs on a C++
compiler? |
Several authors implied that a C++ compiler can compile C programs.
This
is only correct with some restrictions. For example, you can obviously
not use C++ keywords as identifiers. For example, the following is a
legal C program but will fail using C++:
int main() { int class = 0; return class; }
There are a few other cases where C++ has stricter rules than C. For
example, I think in C you can assign a 'void*' to an arbitrary pointer,
e.g. an 'int*' without a cast. In C++ you need an appropriate cast.
However, in general you will be better off using a C++ compiler anyway
because C++ is a more powerful language :-)
Note that you can get good priced C and C++ compilers other than Visual
C++.
For example, the GNU Compiler Collection (GCC) has both a free C and
C++
compiler. Also, Comeau's C++ compiler is pretty cheap (only $50 for a
conforming compiler; all other compilers are either more expensive or
non-conforming - most are both). I think there is a fair selection of
free
C compilers around but I don't know their names because I'm not really
that
interested in C anymore.
--
<mailto:dietmar_kuehl (AT) yahoo (DOT) com> <http://www.dietmar-kuehl.de/>
<http://www.contendix.com> - Software Development & Consulting
[ See http://www.gotw.ca/resources/clcm.htm for info about ]
[ comp.lang.c++.moderated. First time posters: Do this! ]
|
|
| Back to top |
|
 |
Francis Glassborow Guest
|
Posted: Fri Sep 17, 2004 5:42 pm Post subject: Re: Will C pgm compile on C++ compiler? |
|
|
In article <2qt9e2F136nevU7 (AT) uni-berlin (DOT) de>, Nicolas Pavlidis
<pavnic (AT) sbox (DOT) tugraz.at> writes
| Quote: | In C you include stdio.h
In C++ you include
cstdio
You can do that but are certainly not required to. There are real |
incompatibilities but this is not one of them.
--
Francis Glassborow ACCU
Author of 'You Can Do It!' see http://www.spellen.org/youcandoit
For project ideas and contributions: http://www.spellen.org/youcandoit/projects
[ See http://www.gotw.ca/resources/clcm.htm for info about ]
[ comp.lang.c++.moderated. First time posters: Do this! ]
|
|
| Back to top |
|
 |
Michiel Salters Guest
|
Posted: Sat Sep 18, 2004 11:15 am Post subject: Re: Will C pgm compile on C++ compiler? |
|
|
Nicolas Pavlidis <pavnic (AT) sbox (DOT) tugraz.at> wrote
| Quote: | "Ken Applequist" <apple07840 (AT) yahoo (DOT) com> writes:
I had C programming in school years ago and would like to play with it
again. When I go online I only seem to be able to find C++ compilers. I know
that C++ is object oriented, whereas C is not. I can get a good price on
Visual C++ 6.0. Is there a way to run native C programs on a C++
compiler?
It is called C ++, you understand , no sorry.
It works but you will have to change the headers, here is an example:
In C you include stdio.h
In C++ you include cstdio
|
Actually, <stdio.h> will work better for old C programs. If you
change to <cstdio>, you also need to change to std::printf.
Regards,
Michiel Salters
[ See http://www.gotw.ca/resources/clcm.htm for info about ]
[ comp.lang.c++.moderated. First time posters: Do this! ]
|
|
| Back to top |
|
 |
Nicolas Pavlidis Guest
|
Posted: Sun Sep 19, 2004 10:52 am Post subject: Re: Will C pgm compile on C++ compiler? |
|
|
[email]Michiel.Salters (AT) logicacmg (DOT) com[/email] (Michiel Salters) writes:
| Quote: | Nicolas Pavlidis <pavnic (AT) sbox (DOT) tugraz.at> wrote in message
news:<2qt9e2F136nevU7 (AT) uni-berlin (DOT) de>...
In C you include stdio.h
In C++ you include cstdio
Actually, <stdio.h> will work better for old C programs. If you
change to <cstdio>, you also need to change to std::printf.
|
No, I don't think so, but maybe I have a little missunderstanding:
----------8<-------------------snapp------------------------>8----------
#include<cstdio>
int main()
{
printf("Hello World");
return(0);
}
----------8<-------------------snipp------------------------>8----------
This piece of code compiles on g++ 3.4 without any errors or warnings.
But it's true, that it is not necessary to change the headers.
Regards,
Nicolas
--
| Quote: | Nicolas Pavlidis | Elvis Presly: | |__ |
Student of SE & KM | "Into the goto" | |__| |
[email]pavnic (AT) sbox (DOT) tugraz.at[/email] | ICQ #320057056 | |
-------------------University of Technology, Graz----------------|
|
[ See http://www.gotw.ca/resources/clcm.htm for info about ]
[ comp.lang.c++.moderated. First time posters: Do this! ]
|
|
| Back to top |
|
 |
kanze@gabi-soft.fr Guest
|
Posted: Mon Sep 20, 2004 7:07 pm Post subject: Re: Will C pgm compile on C++ compiler? |
|
|
Nicolas Pavlidis <pavnic (AT) sbox (DOT) tugraz.at> wrote
| Quote: | Michiel.Salters (AT) logicacmg (DOT) com (Michiel Salters) writes:
Nicolas Pavlidis <pavnic (AT) sbox (DOT) tugraz.at> wrote in message
news:<2qt9e2F136nevU7 (AT) uni-berlin (DOT) de>...
In C you include stdio.h
In C++ you include cstdio
Actually, <stdio.h> will work better for old C programs. If you
change to <cstdio>, you also need to change to std::printf.
No, I don't think so, but maybe I have a little missunderstanding:
----------8<-------------------snapp------------------------>8----------
#include<cstdio
int main()
{
printf("Hello World");
return(0);
}
----------8<-------------------snipp------------------------>8----------
This piece of code compiles on g++ 3.4 without any errors or warnings.
|
That's because of a bug in g++.
Of course, just about every other compiler has the same bug.
--
James Kanze GABI Software http://www.gabi-soft.fr
Conseils en informatique orientée objet/
Beratung in objektorientierter Datenverarbeitung
9 place Sémard, 78210 St.-Cyr-l'École, France, +33 (0)1 30 23 00 34
[ See http://www.gotw.ca/resources/clcm.htm for info about ]
[ comp.lang.c++.moderated. First time posters: Do this! ]
|
|
| Back to top |
|
 |
kanze@gabi-soft.fr Guest
|
Posted: Mon Sep 20, 2004 7:08 pm Post subject: Re: Will C pgm compile on C++ compiler? |
|
|
[email]Michiel.Salters (AT) logicacmg (DOT) com[/email] (Michiel Salters) wrote in message
news:<fcaee77e.0409160306.27d6ae17 (AT) posting (DOT) google.com>...
| Quote: | "Ken Applequist" <apple07840 (AT) yahoo (DOT) com> wrote in message
news:<Sh%1d.4320$F75.1229@trndny01>...
I had C programming in school years ago and would like to play with
it again. When I go online I only seem to be able to find C++
compilers. I know that C++ is object oriented, whereas C is not. I
can get a good price on Visual C++ 6.0. Is there a way to run native
C programs on a C++ compiler?
C++ is pretty much a superset of good C, so good programs should
continue to run. Some C programs fail for trivial reasons, e.g. using
"class" which then became a keyword.
|
There is one major exception. C programs will generally use malloc to
allocate memory, and it is generally considered bad pratice in C to cast
the return value of malloc to the target type. This works in C, because
a void* converts implicitly to any type of pointer, but this will not
compile with C++.
--
James Kanze GABI Software http://www.gabi-soft.fr
Conseils en informatique orientée objet/
Beratung in objektorientierter Datenverarbeitung
9 place Sémard, 78210 St.-Cyr-l'École, France, +33 (0)1 30 23 00 34
[ See http://www.gotw.ca/resources/clcm.htm for info about ]
[ comp.lang.c++.moderated. First time posters: Do this! ]
|
|
| Back to top |
|
 |
Dietmar Kuehl Guest
|
Posted: Tue Sep 21, 2004 11:40 am Post subject: Re: Will C pgm compile on C++ compiler? |
|
|
Nicolas Pavlidis <pavnic (AT) sbox (DOT) tugraz.at> wrote:
| Quote: | Michiel.Salters (AT) logicacmg (DOT) com (Michiel Salters) writes:
Actually, <stdio.h> will work better for old C programs. If you
change to <cstdio>, you also need to change to std::printf.
No, I don't think so, but maybe I have a little missunderstanding:
----------8<-------------------snapp------------------------>8----------
#include<cstdio
int main()
{
printf("Hello World");
return(0);
}
----------8<-------------------snipp------------------------>8----------
This piece of code compiles on g++ 3.4 without any errors or warnings.
|
If it does compile this code, gcc is not strictly standard conforming!
(well, gcc is not [yet?] strictly standard conforming anyway) See
17.4.1.2 paragraph 4 of the C++ standard and the footnote to paragraph
7 of the same clause. If you have a quote from the standard which
supports your position, let me know.
However, at one of the most recent meetings (actually, I think on the
last meeting) the library working group discussed the definition of C
library names in the global namespace and generally agrees that this
practise shall be legal. You might want to have a look at LWG Issue
456 (<http://www.open-std.org/jtc1/sc22/wg21/docs/lwg-active.html#456>)
whose resolution would sanction gcc's implementation.
--
<mailto:dietmar_kuehl (AT) yahoo (DOT) com> <http://www.dietmar-kuehl.de/>
<http://www.contendix.com> - Software Development & Consulting
[ See http://www.gotw.ca/resources/clcm.htm for info about ]
[ comp.lang.c++.moderated. First time posters: Do this! ]
|
|
| Back to top |
|
 |
Nicolas Pavlidis Guest
|
Posted: Tue Sep 21, 2004 6:39 pm Post subject: Re: Will C pgm compile on C++ compiler? |
|
|
[email]dietmar_kuehl (AT) yahoo (DOT) com[/email] (Dietmar Kuehl) writes:
| Quote: | Nicolas Pavlidis <pavnic (AT) sbox (DOT) tugraz.at> wrote:
[email]Michiel.Salters (AT) logicacmg (DOT) com[/email] (Michiel Salters) writes:
Actually, <stdio.h> will work better for old C programs. If you
change to <cstdio>, you also need to change to std::printf.
No, I don't think so, but maybe I have a little missunderstanding:
----------8<-------------------snapp------------------------>8----------
#include<cstdio
int main()
{
printf("Hello World");
return(0);
}
----------8<-------------------snipp------------------------>8----------
This piece of code compiles on g++ 3.4 without any errors or warnings.
If it does compile this code, gcc is not strictly standard conforming!
(well, gcc is not [yet?] strictly standard conforming anyway) See
|
Comaeu 4.3.3 does not complain too (in strict mode).
| Quote: | 17.4.1.2 paragraph 4 of the C++ standard and the footnote to paragraph
7 of the same clause. If you have a quote from the standard which
supports your position, let me know.
|
Ok.
| Quote: | However, at one of the most recent meetings (actually, I think on the
last meeting) the library working group discussed the definition of C
library names in the global namespace and generally agrees that this
practise shall be legal. You might want to have a look at LWG Issue
456 (<http://www.open-std.org/jtc1/sc22/wg21/docs/lwg-active.html#456>)
whose resolution would sanction gcc's implementation.
|
Ok, thank you.
Kind regards,
Nicolas
--
| Quote: | Nicolas Pavlidis | Elvis Presly: | |__ |
Student of SE & KM | "Into the goto" | |__| |
[email]pavnic (AT) sbox (DOT) tugraz.at[/email] | ICQ #320057056 | |
-------------------University of Technology, Graz----------------|
|
[ See http://www.gotw.ca/resources/clcm.htm for info about ]
[ comp.lang.c++.moderated. First time posters: Do this! ]
|
|
| Back to top |
|
 |
|
|
You cannot post new topics in this forum You cannot reply to topics in this forum You cannot edit your posts in this forum You cannot delete your posts in this forum You cannot vote in polls in this forum
|
|