Welcome, %1$s. Please login or register.

August 22, 2017, 10:56:05 AM
: 1
: C over C++!  ( 4812 )
« : October 26, 2007, 11:23:58 PM From Shrinidhi»

C over C++!

Can anyone tell why C is still preferred over C++ at some places?
i.e. We all know the advantages of C++ over C, but are there any advantages of C over C++?

Liked It? Share it!


« #1 : October 28, 2007, 11:21:13 PM From spazinvader»

I know one.
C allows direct access of variables in an input structure.In C++,methods are called to gain access to the variables' values.So we cannot directly access variables in an input structure.
« #2 : October 30, 2007, 06:56:00 PM From Poonam»

Spazinvader, you cannot say that as an advantage. Even in C++ one can access the member variables of a structure/class by declaring them as public.

« #3 : October 30, 2007, 07:07:15 PM From Poonam»

My personal feeling is that a C code base is easily portable when compared to a C++. Also a C code is more readable.
« #4 : November 12, 2007, 07:08:14 PM From Rahul»

c language is used for writing codes for hardware intrection that can not be written in c++
inshprt c is used as interface while c++ cannot
cant explain in much  better way
« #5 : November 12, 2007, 10:22:56 PM From spazinvader»

It is an advantage for C over C++.
But java can do the job in a simple way right?
My guess is that we can easily co ordinate with the programs with new ones as there will not be data hiding concept in C.
« #6 : November 14, 2007, 07:26:57 PM From Rahul»

i agree but this could also be possible in c++ if we want n in much better way

« #7 : November 19, 2007, 06:52:20 PM From iammilind»

Technically, there is no advantage of C over C++. Following are few misconceptions.

(1) C supports implicit typecasting, C++ doesn't
int *pi; struct A *pA; pi = pA; // True for C but not for C++
Note that above statement gives compilation error in C++ and modern C compilers too ! This "strength" is shrinked(with explicit typecast) by C++ to avoid logical errors/hazards.

(2) C++ has more overhead than C (i.e. C is faster)
This is the most infamous misunderstanding, because of two reasons:
(i) Not using a good C++ compiler for embedded or general purpose systems
e.g. some compilers are made so powerful that they will generate a little faster code for 'cout' than 'printf'.

(ii) Using the strengths of C++ and then, ridicule them by saying it is slower
e.g. For better code viewability, programmer uses virtual polymorphism. This concept takes the run-time decision that which class function to be called. So naturally it will be slower. But if you try to implement the same in C with its function pointer syntax, it will take the same amount of time.

(3) C++ generates bigger code than C
The answer is same as above. If you use simple features like function overloading, encapsulation, etc. there is no bigger code at all. But if you use higher level C++ features, which are complex to implement in C, it will naturally generate a bigger (though cleaner) code. Smaller C++ code can be written by following.
e.g. (i) Leave constructors-destructors empty
(ii) Don't put any function members in class, but use the class only for encapsulation
(iii) Use inline for smaller functions

(4) C provides better visibility of code than C++
100% wrong. This is because of lack of command on C++ and mad love for C
Moreover, to our surprise, enum,const and inline are the 3 features of C++ which are inherited in C (to avoid dangerous macros) for cleaner code.
In C it is impossible to implement private,protected types, function overloading, operator overloading and many other features. All these features will help to create a better viewability (and there are lot many OOP features also).

One can refer following website of Bjarne Stroustrup(creator of C++):
« #8 : January 10, 2008, 01:38:38 PM From thequark»

1) Writing a C compiler is much easy. So release a chip, decide on ISA and all that and create a C compiler for that.

2) Mapping of generated assembly code is much easier in C rather than C++

3) Writing portable code i.e. availability of compiler, library, etc. i __feel__ is better in C, C++. It is easy to write portable and non portable code in C [Do I have to tell you that Shrinidhi :), this is Prateek]
« #9 : January 10, 2008, 07:02:14 PM From iammilind»


  Does it seemt that you are comparing both the languages with respect to compilers only ? What we discuss is based on the language.
1) "writing C compiler much easier than C++"
-> naturally C provides less features

2) "Mapping of generated assembly code is much easier in C rather than C++"
-> can you plz provide any link to support this in all aspects, because in VC++ it looks same !

3) "Writing portable code i.e. availability of compiler, library, etc. i __feel__ is better in C"-> portable code depends on programmer, for availability of compiler just google for C++0x and now a days we have many good C++ compilers which can even generate less amount of code than C (for cout and printf) (Bjarne Stroustrup official website)

one good note:
Java's development was so big and centralized to Sun Microsystem that, virtually no one tried to create another JVM (sort of Java compiler) for that. That went on to prove Java as a platform independent language !! That means it is having only one 'compiler' and still it is platform independent, does it really mean that ??
« #10 : January 22, 2008, 09:58:28 AM From thequark»


1. I agree. But the point still holds true. C has advantage over C++ for embedded systems

2. Mapping not through a tool but a _mental_ map (however silly this might sound). A programmer or a technical leader with sufficient knowledge of instruction set architecture and code generation can know what the code generated would be like. What segment goes where. Which part of data goes for BSS, stack etc.

3. Things like boost pointer etc. do not guarantee portability or availability for every platform.

: 1
« previous next »


Best RatedList All>>


SMF 2.0.10 | SMF © 2015, Simple Machines | Contact Webmaster | OnlineFunDb.com © 2009/10 | Legal Disclaimer