Excluding a lot of other things... These are 2 different languagesThis is because code that is C++ compliant will also compile under C, excluding classes.
Where do you have new/delete in C?
Or function overloading?
Excluding a lot of other things... These are 2 different languagesThis is because code that is C++ compliant will also compile under C, excluding classes.
Where do you have new/delete in C?
Or function overloading?
All problems in computer science can be solved by another level of indirection,
except for the problem of too many layers of indirection.
– David J. Wheeler
Actually it is quite the other way around. For the most part, any C program will compile successfully with a C++ compiler...but there is no possible way for a C compiler to compile a pure C++ program.This is because code that is C++ compliant will also compile under C, excluding classes. Code that compiles under C may not necessarily compile as C++.
This is growing less true, however. Although I have not tested any specific cases myself, I have heard lately that C++ has begun to diverge enough from C that not all C code is compilable in C++ compilers anymore.
Here's a list of why that is wrong...
# anonymous unions
# classes
# constructors and destructors
# exceptions and try/catch blocks
# external function linkages (e.g., extern "C")
# function overloading
# member functions
# namespaces
# new and delete operators and functions
# operator overloading
# reference types
# standard template library (STL)
# template classes
# template functions
# // comments
How I need a drink, alcoholic in nature, after the heavy lectures involving quantum mechanics.
> I have heard lately that C++ has begun to diverge enough from C that not all C code
> is compilable in C++ compilers anymore.
It was never true from the beginning, never mind now.
All those extra keywords added by C++, like class. They're perfectly valid C identifiers. So right from the beginning
int class;
would cause a C++ compiler to barf.
http://david.tribble.com/text/cdiffs.htm
If you dance barefoot on the broken glass of undefined behaviour, you've got to expect the occasional cut.
If at first you don't succeed, try writing your phone number on the exam paper.
15 years ago, when I was in college, there were people already in there that were saying(Please note that I know the difference between an idiot CS Student and a good CS Student).Originally Posted by Idiot CS Students
I want to second Salem on this one. A "real" programmer would be one that 1) knows HOW to program, 2) knows HOW to learn a language, 3) knows HOW things work BEFORE he/she begins to work on the project, and 4) is not afraid to attempt to solve a problem in some other language -- even if he/she does not know that language.
It would seem that we are getting too far removed from the KISS model of programming. When one uses something like VB/Java to do hardware programming, one can expect problems to occur later.
My 0.02 USD.
since new/delete is primarily for creating/destroying classes new instantiations of classes, this woudl fall under classes. otherwise you can just use malloc/free which have the exact same effect when applied to things other than classes. Cry about malloc/free not being part of C, but they are in EVERY standard library out there. I know of no working implementation that does not include them, although im sure someone will find some little known example to try to 'prove' me wrong.
As for function overloading, its called function renaming, The C++ preprocessor just handles it automatically for you. So again, other than classes, there arent any intrinsic differences between C and C++. You can take a C compiler and easily add those features that woudl mke it a C++ compiler. Not so with a different language like Java or VB or COBOL, Fortran, Ada, ML etc. Try upgrading Clipper to C++ and you will understand what a different language means. Going from C to C++ is trivial.
Last edited by abachler; 01-09-2008 at 04:24 PM.
>Cry about malloc/free not being part of C, but they are in EVERY standard library out there.
Well, the only problem with that statement is that malloc and free are Standard functions. Sure, people will reimplement the Standard from time to time (dmalloc) to add something, but that statement is just wrong. For all intents and purposes it is a part of C.
Wow, can you? I cant C++ has quite a lot of useful features. Templates rule!You can take a C compiler and easily add those features that woudl mke it a C++ compiler.
You're right, function overloading is usually implemented by "mangling" the names of the functions to include some information about the function's arguments. However, it's the compiler that does this, not the preprocessor. The preprocessor does very few things, among them:
- File inclusion with #include.
- Conditional compilation with #if etc.
- Macros with #define.
- Comments (the preprocessor strips them).
- String literal concatenation.
The first C++ "compiler" was actually a source-to-source translator: it simply converted C++ into C. So every feature of C++ can be represented in C. In fact, every feature of C++ can be represented in assembly -- that's how compilers can exist.
But that doesn't mean we should be programming directly in assembly just because C++ can be converted into assembly. It's convenience, and abstraction, that makes us use higher-level languages.
dwk
Seek and ye shall find. quaere et invenies.
"Simplicity does not precede complexity, but follows it." -- Alan Perlis
"Testing can only prove the presence of bugs, not their absence." -- Edsger Dijkstra
"The only real mistake is the one from which we learn nothing." -- John Powell
Other boards: DaniWeb, TPS
Unofficial Wiki FAQ: cpwiki.sf.net
My website: http://dwks.theprogrammingsite.com/
Projects: codeform, xuni, atlantis, nort, etc.
it is for dynamic memory allocation, what it has to do with classes? If you do not use classes?since new/delete is primarily for creating/destroying classes
Code:int* arr = new int[15];
All problems in computer science can be solved by another level of indirection,
except for the problem of too many layers of indirection.
– David J. Wheeler
I dont disagree with you dwks, but I dont see C++ as a seperate language from C. It has more features for sure, just as modern english is more descriptive than english of say 100 years ago. Both can be translated into grunts whistles and other basic phoenetic primitives. That doesnt make 19th century english and modern english 2 seperate languages, nor does it mean we should all go around speaking in phoenetics either. I can obviously translate any modern phrases into terms in use in the 19th century, granted it woudl take longer to express teh same concepts, just as it woudl take more lines of code to express the same behavior in C as in C++. Again, this does not make them seperate languages, merely differnt dialects at most.
new/delete is the primary way to instantiate a class. it is a bit difficult to instantiate a class using malloc. I really fail to see what you are asking?
can be just as easily expressed in C asCode:int* arr = new int[15];
Code:int* arr = malloc(15 * sizeof(int));
Last edited by abachler; 01-09-2008 at 11:10 PM.
That's the idea - use C when you need C, do not use C++ because you anyway will need to rewrite the code to compile it as Ccan be just as easily expressed in C as
All problems in computer science can be solved by another level of indirection,
except for the problem of too many layers of indirection.
– David J. Wheeler
C and C++ are considerably less similar than C# and Java. Does that make Java and C# "merely dialects" of the same language?
All the buzzt!
CornedBee
"There is not now, nor has there ever been, nor will there ever be, any programming language in which it is the least bit difficult to write bad code."
- Flon's Law
heheh, geneticists argue that tracing common ancestry based on morphological features is less reliable than using DNA. Borrowing their point of view, can C++, C# and Java trace their ancestry from C (and so are part of one C family), or is only C++ a direct descendant from C and thus a dialect of C, whereas C# and Java are entirely different languages?
Look up a C++ Reference and learn How To Ask Questions The Smart WayOriginally Posted by Bjarne Stroustrup (2000-10-14)
Well, both C# and Java can directly trace their ancestry to C++. In the family of programming languages, C# and Java are siblings, children of C++ and Smalltalk, really. C++ is a child of mostly C and Simula.
The main difference is that C++ was developed with C source and binary compatibility in mind, whereas C# and Java had no such ambitions, neither with C++ nor with each other.
All the buzzt!
CornedBee
"There is not now, nor has there ever been, nor will there ever be, any programming language in which it is the least bit difficult to write bad code."
- Flon's Law