- #36
ElijahRockers
Gold Member
- 270
- 10
One of my TAs, when I asked him this very question, (C vs C++) likened the difference to that of driving a standard transmission automobile (C) to an automatic transmission (C++).
This makes sense in a way, but I think it's a little misleading. C++ is a much more complex language than C. Maybe you could say C++ coding is like a mix of building or modifying automatic transmissions and using them.ElijahRockers said:One of my TAs, when I asked him this very question, (C vs C++) likened the difference to that of driving a standard transmission automobile (C) to an automatic transmission (C++).
tAllan said:it's a little misleading. C++ is a much more complex language than C. Maybe you could say C++ coding is like a mix of building automatic transmissions and using them.
ElijahRockers said:One of my TAs, when I asked him this very question, (C vs C++) likened the difference to that of driving a standard transmission automobile (C) to an automatic transmission (C++).
Yes, yes, sorry. I type before I think. (some staff gave me a warning about that )D H said:Linkers are beasts born in the late 1950s. While they've changed a bit since then (e.g., dynamic libraries, weak symbols), the basic concept remains the same. There's no place in that 50+ year old concept for the same function in multiple namespaces, multiple classes, or for different overloads of the same function, which means that every C++ implementation has to use some kind of name mangling. How that works is highly implementation-specific.cdecl is a Microsoft-specific concept. There's nothing in the C or C++ standard that addresses cdecl. Except for code wrapped with lots if #ifdef this, #ifdef that, etc., you won't find any code targeted for a POSIX implementation that uses cdecl. What you occasionally will find is code declared as having extern "C" linkage. This latter concept is something that is in the C++standard, and it essentially means "don't use name mangling."
The above does not mean that C++ code cannot be linked to other languages. The Boost.Python library provides interoperability between C++ and python. SWIG goes several steps further, providing interoperability between C/C++ code and Javascript, Perl, PHP, Python, Tcl Ruby, C#, Common Lisp, D, Go, Java, Lua, Modula-3, OCAML, Octave, Scilab and R.
Stephanus said:I'm sorry, this is not my thread. But I am just curious.
If we throw all c source files and all it's .obj library (either from another c or assembly) and its c headers to a C++ compiler,
1. Would the compiler compile them perfectly?
2. Will C++ compiler generates executable 100% match as C compilier, perhaps there's a difference in .exe header or relocation table, but is it 99.99% matches?
Thanks.
Okay, what I mean is the result will be exactly the same, right.Hornbein said:Two C compilers will generate different output. It's up to the compiler writer.
Quite a lot of C code will successfully compile with a C++ compiler, (although the compiler might give warnings about non standard coding it still will produce a working result).Stephanus said:I have no idea how in the .obj file these two functions coexist together.
Amine Quentin said:Hi Guys
Do I need to learn C before C ++?
Yes, I agree. If one knows C very well; procedure calling; looping; structure; pointer; variable type; then in C++ one only has to learn the OOP concept and a little about operator overloading.jack476 said:They're basically the same language, C++ is only an extension of C. If you know one well, then the other will be easy, but there's no real reason to learn either one first.
In retrospect, I'm glad I learned C before C++ (due to requirements for my major, the C class was freshman year, C++ came much later for me) because there's just much less material that needs to be covered and it was easier to "graduate" to C++ once I had experience with the weaknesses of C that C++ was meant to improve on.
On the other hand, C++ is a much more common language than C, and it's usually the standard in programming businesses and one of the languages that a programmer must know at bare minimum, so there's also a case to be made for doing C++ first and then going to C if you're curious about where C++ comes from.
NO NO NO. You ABSOLUTELY need to learn C before you learn C++ PERIOD.jack476 said:They're basically the same language, C++ is only an extension of C. If you know one well, then the other will be easy, but there's no real reason to learn either one first.
In retrospect, I'm glad I learned C before C++ (due to requirements for my major, the C class was freshman year, C++ came much later for me) because there's just much less material that needs to be covered and it was easier to "graduate" to C++ once I had experience with the weaknesses of C that C++ was meant to improve on.
On the other hand, C++ is a much more common language than C, and it's usually the standard in programming businesses and one of the languages that a programmer must know at bare minimum, so there's also a case to be made for doing C++ first and then going to C if you're curious about where C++ comes from.
Since C source codes can be compiled by C++ compiler. There's nothing wrong with learning C++.meBigGuy said:NO NO NO. You ABSOLUTELY need to learn C before you learn C++ PERIOD.
rcgldr said:You can learn both at the same time...
No, it's not "like" C when you do that, it IS C.Stephanus said:Since C source codes can be compiled by C++ compiler. There's nothing wrong with learning C++.
You can learn C++ without OOP and operator overloading and function overloading and it's like C before you know you compile it by C++ compiler. As @rcgldr says,
Impressive isn't it. It's two entirely different languages yet very much alike.phinds said:No, it's not "like" C when you do that, it IS C.
I don't understand what you are talking about. What do you mean they are "two entirely different languages" ? C++ is just OOP put on top of C.Stephanus said:Impressive isn't it. It's two entirely different languages yet very much alike.
You are right, C++ supersedes C but on one hand a very large number of core libraries developed during the time C came along are heavily dependent on C. Industrial and business needs are, on the other hand, relying on the management of time frame and budget, so all of a sudden people can't take risk to upgrade their systems to latest technologies that use C++ or the likes and at the same time security issues have also been brought up a lot like plagues or pathogens the human have to fight against.phinds said:I don't understand what you are talking about. What do you mean they are "two entirely different languages" ? C++ is just OOP put on top of C.
You are making exactly the point I have been propounding all along. It seems to me that you are agreeing with me while disagreeing with me.meBigGuy said:I feel very strongly about this. The fact that C++ is C is meaningless (although it is true). When you go into ANY C++ class there will be assumptions about how much C you know. Please read my example above regarding building a linked list class. And it isn't like the C++ class is going to spend time teaching everyone about C basics like pointers, arrays, and the like.
If you talk to the professor and he specifically says that he will teach C++ beginning with the assumption that the students have zero C knowledge, then possibly I'll relent. But, even then, you will learn more if you know C going in.
Again, the fact that C++ is based on C is meaningless in this context. The C++ constructs are built on top of (out of) C, and you should understand basic C going in. You use a lot of basic C in any C++ program.
Not merely C plus OOP, but the operator overloading is a very new concept.phinds said:You are making exactly the point I have been propounding all along. It seems to me that you are agreeing with me while disagreeing with me.
You say "The C++ constructs are built on top of (out of) C, and you should understand basic C going in" which is exactly what I mean when I say that C++ is just C plus the OOP constructs.
I consider overloading to be part of the OOP constructs.Stephanus said:Not merely C plus OOP, but the operator overloading is a very new concept.
Of course you can't make operator overloading without class definition.
cin and cout are the most common objects.
But in Delphi, there's no operator overloading. OOP doesn't have to have operator overloading. But, you can't do operator overloading without OOP. Furthermore in C++ there is function overloading feature, right. Doesn't have anything to do with OOP.phinds said:I consider overloading to be part of the OOP constructs.
meBigGuy said:If you talk to the professor and he specifically says that he will teach C++ beginning with the assumption that the students have zero C knowledge, then possibly I'll relent.
Stroustrup created C++ on top of C. That's why I keep saying that C++ is just C plus OOP stuff (and as you seem conflicted about, but are clearly aware of, overloading only comes with the OOP stuff).Stephanus said:Sorry, it's Bjarne Stroustrup
https://en.wikipedia.org/wiki/C++
Who is Dennis Ritchie? I have his book.
Wait..
Ah there he is: https://en.wikipedia.org/wiki/Dennis_Ritchie
Ahh, died in 2011. At the same time as Steven Jobs as I recall.
RIP Dennis Ritchie...
Dennis Ritchie is one-half of the acronym "K & R" which is very well-known to all long-time C programmers. Brian Kernighan (the 'K' of K & R) and Dennis Ritchie (the 'R' of K & R) wrote "The C Programming Language" back when they worked at Bell Labs.Stephanus said:Sorry, it's Bjarne Stroustrup
https://en.wikipedia.org/wiki/C++
Who is Dennis Ritchie? I have his book.
Stephanus said:Wait..
Ah there he is: https://en.wikipedia.org/wiki/Dennis_Ritchie
Ahh, died in 2011. At the same time as Steven Jobs as I recall.
RIP Dennis Ritchie...
phinds said:Stroustrup created C++ on top of C.
That's why I keep saying that C++ is just C plus OOP stuff
To use operator overloading, you need OOP.phinds said:Stroustrup created C++ on top of C. That's why I keep saying that C++ is just C plus OOP stuff (and as you seem conflicted about, but are clearly aware of, overloading only comes with the OOP stuff).
I'm pretty sure Herb Schildt didn't include a compiler with any of his books.Stephanus said:But I am not astonished, because only in C do the programming language has its fanatics.
I have (had?, don't know where the book now) a book. It's "Born to Code in C". The author is Herbert Schildt.
There is a semaphore programming in his books. And if I'm not mistaken, there is a simple compiler, or there isn't.
I'm going to say that you definitely can't put functions/methods in an enumeration (why would you want to?), and I don't think you can put them in a union. If you can, I've never seen an example of it.Stephanus said:And if you don't use function overloading, and class definition, then it's C.
If I recall correctly, in C++ we can even put methods in union and struct, not just class. I don't know about enum. Can we do that in Enum?
It's been 20 years since I learn C++. I'm using C now. But I remembered something like "member function in union"Mark44 said:I'm pretty sure Herb Schildt didn't include a compiler with any of his books.I'm going to say that you definitely can't put functions/methods in an enumeration (why would you want to?), and I don't think you can put them in a union. If you can, I've never seen an example of it.
You can have C structs with member functions -- by using function pointers.
Yes, member function in enum really doesn't make any sense.Code:template<typename T> unionFoo{ public: Foo(){} Foo(const T& value): _val(value){} constchar* data()const{ return _tab; } std::size_t size()const{ returnsizeof(T); } charoperator[](unsignedint index)const{ return _tab[index]; } private: T _val; char _tab[sizeof(T)]; }
No, it's not that we have a function pointer element in a struct. But it's a real method.Mark44 said:...
You can have C structs with member functions -- by using function pointers.