Take the 2-minute tour ×
Programmers Stack Exchange is a question and answer site for professional programmers interested in conceptual questions about software development. It's 100% free, no registration required.

What features were added to C that were originally in C++?
When where they added and for what reason(what where the pro/con arguments)?
How do they differ in C as compared to C++?

Did the features originate in C++ or in another language?

Examples (feel free to expand on): const, Function prototypes, implicit exit(0);

share|improve this question

4 Answers 4

up vote 11 down vote accepted

A few that I can think of that were added for C99. bool is not quite the same as C++ since you need to include a header to use it, the others are implemented the same as C++.

  • bool / true / false
  • // comments
  • inline functions
  • variables don't need to be declared at start of block
share|improve this answer
3  
The bool type in C99 is _Bool. bool is just a macro in stdbool.h expanding to _Bool. Similarly true and false are macros for 1 and 0. I'm pretty sure they implemented it in this way give the programmer the option to be compatible with C++. –  user29079 Aug 12 '11 at 13:55

Same answer than in SO: the best and most pertinent source is Bjarne's paper. You could probably grab one piece of information or another in sources like The Design and Evolution of C++ or the papers on the history of C and C++ in the proceedings of HOPL, but I don't remember anything specific there, especially in the direction C++ to C.

share|improve this answer

The only technical differences I'm aware of migrating in that direction are the C99 enhancements like not having to declare variables at the start of functions. A number of style items migrated due to the fact that C programs are occasionally compiled with C++ compilers to be included as part of a C++ program. This includes avoiding the use of C++ reserved words like "class" and gratuitous typecasts (like on the result of malloc) that are required in C++ but are implicit in C.

share|improve this answer
2  
Didn't "line" style comments (//such as this example) also go from C++ to C? –  FrustratedWithFormsDesigner Aug 10 '11 at 13:36
2  
@FrustratedWithFormsDesigner Actually they went from B to C++ to C. –  h0b0 Aug 10 '11 at 14:08
    
Line-style comments were one of the C99 enhancements, @Frustrated. However, I do remember those being one of the more popular unofficial compiler-specific extensions long before they were formalized as a standard. –  Karl Bielefeldt Aug 10 '11 at 15:20
1  
I suspect that typecasting the result of functions returning void, such as malloc, is most commonly caused by confused C programmers trying to compile their code on a C++ compiler, and less commonly an intention to be C++ compatible. It should also be mentioned that typecasting the result of void* functions in C is considered bad practice, as it effectively disables a number of static type checks that the compiler and/or external tools could otherwise have done to find bugs. –  user29079 Aug 12 '11 at 14:07
    
The malloc cast topic is discussed in detail in countless SO threads such as this one. –  user29079 Aug 12 '11 at 14:07

basically C++ comes from C, the common part between both languages is called C- . The C++ is "bigger/better" than C, but the main thing is that it's a fully object oriented programming language and C isn't.

share|improve this answer
5  
Well current C and C++ share a common ancestor (say K&R C), but there are strong cross-influence (positive or negative, one sometimes get the impression that some want to increase the incompatibility between the two). –  AProgrammer Aug 10 '11 at 11:42
    
C++ is a superset of C, but it's not strict. So you wind up with code that is valid C such as void *ptr; int *ptr2 = ptr; which is not valid in C++. This is in contrast to something like Objective C, which is a strict superset of C. Because of this, "all" valid C code is also valid Objective C code. –  Barry Aug 10 '11 at 15:45
    
I've never heard of C- before, though I have heard of C--. Do you have any reliable source for this C- thing? –  user29079 Aug 12 '11 at 14:10
    
I read it long ago on a C++ book. I would have to consult that book to assure such a thing. –  Feida Kila Aug 30 '11 at 13:38

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.