Welcome Guest ( Log In | Register )



 
Reply to this topicStart new topic
> Did I Install A C Or A C++ Compiler ?, A simple way to see the difference
yordan
post May 23 2007, 03:30 PM
Post #1


Way Out Of Control - You need a life :)
Group Icon

Group: [MODERATOR]
Posts: 2,043
Joined: 16-August 05
Member No.: 7,896



If you already had the same problem I just experienced, you should probably be interested by this trick.
I just installed a compiler, and I wanted to know if I installed the C and the C++ compiler, or only the C compiler.
The answer is simple : let's use small sample programs.
Everybody know the well-known "hello" world C program, it compiles with a standard C compiler.
CODE
main ()
{
printf("Hi, Folks, what s new");
}


And here is a sample C++ "hello world" program :
CODE
#include <iostream.h>
main()
{
    cout << "Hello World!";
    return 0;
}

The second sample program compiles only with a C++ compiler, the standard C compiler gives an error for the "cout" syntax.
So, using these two small pieces of code allows you to check that you have both the standard C and the C++ compilers.
Hope this helps you as it helped me.
Regards
Yordan
Reason for edit: HTML tags in CODE block
Go to the top of the page
 
+Quote Post
WeaponX
post May 23 2007, 10:48 PM
Post #2


Way Out Of Control - You need a life :)
Group Icon

Group: Members
Posts: 1,086
Joined: 21-June 05
From: New York
Member No.: 6,440



Haven't used those compilers that were meant only for C or only for C++. The ones I tried usually compiles both, but that's definitely a good thing to know. Even Borland's Turbo C++ (name implies that it's a C++ compiler) works with the C language smile.gif
Go to the top of the page
 
+Quote Post
miCRoSCoPiC^eaRt...
post May 24 2007, 02:57 AM
Post #3


PsYcheDeLiC dR3aMeR
Group Icon

Group: Admin
Posts: 2,242
Joined: 29-January 05
From: Nakorn Chaisri, Thailand
Member No.: 2,411



QUOTE(WeaponX @ May 24 2007, 05:48 AM) *
Haven't used those compilers that were meant only for C or only for C++. The ones I tried usually compiles both, but that's definitely a good thing to know. Even Borland's Turbo C++ (name implies that it's a C++ compiler) works with the C language smile.gif


Yep - all C++ compilers are supposed to be backward compatible, i.e. be able to compile C code as well. That is a standardised rule.
Go to the top of the page
 
+Quote Post
yordan
post May 24 2007, 01:35 PM
Post #4


Way Out Of Control - You need a life :)
Group Icon

Group: [MODERATOR]
Posts: 2,043
Joined: 16-August 05
Member No.: 7,896



QUOTE(miCRoSCoPiC^eaRthLinG @ May 24 2007, 04:57 AM) *
Yep - all C++ compilers are supposed to be backward compatible, i.e. be able to compile C code as well. That is a standardised rule.

Yes, and the trap is that C-only compilers won't compile C++ programs. So, if you prepare a system for somebody else, you should better verify it before calling your collegue, or you will have to pay an apologizing beer.
By the way, I wrote this in the "How-To's" section, because there is no "Tricks and Tips" section.

This post has been edited by yordan: May 24 2007, 01:37 PM
Go to the top of the page
 
+Quote Post
tombert
post Sep 8 2008, 03:01 AM
Post #5


Newbie [ Level 1 ]
Group Icon

Group: Members
Posts: 1
Joined: 8-September 08
Member No.: 32,497



You forgot your namespaces! It probably won't compile with most compilers to begin with now.
Go to the top of the page
 
+Quote Post
Pratyusa
post Sep 8 2008, 08:52 PM
Post #6


Newbie [ Level 1 ]
Group Icon

Group: Members
Posts: 3
Joined: 8-September 08
Member No.: 32,508



QUOTE(tombert @ Sep 8 2008, 08:31 AM) *
You forgot your namespaces! It probably won't compile with most compilers to begin with now.

Practically speaking most of the compilers are built to compile both C and C++ programs. You will hardly find any compiler only meant for C only..
Go to the top of the page
 
+Quote Post
Quatrux
post Sep 9 2008, 05:51 AM
Post #7


the Q
Group Icon

Group: [HOSTED]
Posts: 1,053
Joined: 13-July 05
From: Lithuania, Vilnius
Member No.: 7,059



you can find older compilers which will only compile C language and won't understand C++ but these days I also believe you can hardly find one, unless it's a custom one made but some guy which is open-source, but use the same tools.. If your code can compile C++ it really can compile C language..

the difference I saw with using different compilers, both seem to compile the same little code, but the executable files are much bigger in size of bytes when compiling with Microsoft Visual Studio, when a simple other compiler from the Internet, they seem both to work the same, I remember in the old days people/programmers managed to create really very cool programs or demos (graphics show) in size of 4kb or 16kb now even a hello world is ~240kb biggrin.gif
Go to the top of the page
 
+Quote Post

Reply to this topicStart new topic

Collapse

> Similar Topics

Topics Topics
  1. Why Can't I Install Software As Root?(7)
  2. Looking For A Good C++ Compiler(18)
  3. Notebook Or Laptop?(16)
  4. How To Connect Dual/triple Monitor + Advantages(21)
  5. Alt Txt Tooltip Popups Over Text Links, How To Do?(11)
  6. How To Install Applications In Fedora(12)
  7. PHP Tutorial: Form Verification And Simple Validation(12)
  8. Games For Samsung D900(3)
  9. Installing Glut To Dev C++(3)
  10. Fedora Core 6 Install Problem(6)
  11. Oracle 10g Install Issues(27)
  12. Looking For Linux(34)
  13. Very Simple Login-script(18)
  14. A Simple Register Script(3)
  15. Gimp: Working With Text(5)
  1. How To Install Linux Suse(1)
  2. Myspace Gold Script(2)
  3. Linux For Beginners- Easy To Install(15)
  4. Strange Error When Trying To Install Fedora Core 9(5)
  5. C/c++ -gdb Linux Debug Tool(1)
  6. Simple Java Question(3)
  7. Mccodes V2(6)
  8. How To Install Windows Xp Professional(3)
  9. How To Make Simple Animations In The Gimp(2)
  10. How To Understand A Database Schema(4)
  11. Linux Software Installation Help(2)
  12. How To Re-install Office 2003 Trial(1)
  13. [fl]snow Effect(4)


 



- Lo-Fi Version Time is now: 12th October 2008 - 08:52 PM