Do I need to learn C before C ++?

  • Thread starter Amine Quentin
  • Start date
In summary: C.2. Then we did a long course (9 months at half pace while at the same time doing two half rate math courses Calculus and Algebra courses in parallel; AKA the good...er old fashioned way) in C++.3. We then took the first two courses in C++ and did one semester of design and implementation in a real project.4. We then took the last two courses in C++ and did one semester of design and implementation in a real project.In summary, the order is:-C-C++-Design and implementation in a real project-Design and implementation in a real project
  • #36
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++).
 
Technology news on Phys.org
  • #37
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++).
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.
 
  • #38
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.

Well if you think about it, automatic transmissions are more complicated than standard transmissions also. If C++ makes large projects more manageable, and the goal of "moving the car" is likened to large programming projects, then maybe it still works.

But I see what you mean.
 
  • #39
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++).

Hmm. But C++ takes more effort to write, while automatic transmission requires less effort.

To me, C++ is like circuit boards plugged into bus, while C is point-to-point wiring. A bad C++ program is like both: circuit boards connected by point-to-point wiring. The worst of both worlds.

I like formal declarations of interfaces. I don't see any disadvantage to it for high level code. I never tried to use it for real-time software.
 
  • Like
Likes ElijahRockers
  • #40
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.
Yes, yes, sorry. I type before I think. (some staff gave me a warning about that :smile:)
The question is "Is every .obj file can be linked with by every compiler, is function with cdecl declaration can be linked with any other languages"
I forgot that cdecl only works for a function, as @Svein points out before. cdecl doesn't work for the whole .obj files. Even if you have one function declared with cdecl prefix (or sufix) the other function overloading can make confunsion.
 
  • #41
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.
 
  • #42
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.

Two C compilers will generate different output. It's up to the compiler writer.
 
  • Like
Likes ElijahRockers
  • #43
My whole point is that after a C++ class you will be very skilled at C. You SHOULD do that before the class, and if you do, you will have capacity and understanding to better learn C++. You will use almost all of your C skills when you write C++. So not having to learn C in the C++ class leaves to able to absorb more of the C++ subtleties. I feel very strong about this, having done it the wrong way myself. I'm repeating it because the thread is all over the place.
 
  • #44
Hornbein said:
Two C compilers will generate different output. It's up to the compiler writer.
Okay, what I mean is the result will be exactly the same, right.
You write a C code to calculate, say.. the orbit of the moon. And throw the codes to C++ compiler, its executable will still calculate the orbit of the moon.
But if we change the process
Throw C++ source codes to C...
 
  • #45
Stephanus said:
I have no idea how in the .obj file these two functions coexist together.
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).
You cannot get a C compiler to make a working result from code that uses C++ objects, C++ libraries, and such.
 
  • #46
Amine Quentin said:
Hi Guys
Do I need to learn C before C ++?

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.
 
  • #47
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.
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.
 
  • #48
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.
For example, say your first assignment is a simple linked list class. If you know C and can implement a linked list, then it is a simple C++ assignment to encapsulate it in a class and provide methods, constructors, destructors, etc. If you don't know C you will spend a week learning how to write C to implement a linked list before you can even begin to think about making it a class. You don't even know how to do basic .h files.

Taking a C++ class without knowing C at all will be impossible. I tried it with mediocre C skills and suffered immensely.
 
  • #49
You can learn both at the same time, switching between C and C++ is not that big a deal, even while learning. Depending on the project you're working on, C may be all you need. If using something from C++ standard template library, then you'll need C++ for that project. The projects that you work on while learning are more of an issue than whether you use C or C++.

In the case of school, what matters if there is an introduction to programming class that uses C and/or C++.

At some point, you may want to spend a few weeks learning assembler with very simple projects for a basuc understanding of how programs work. I'm not sure if it's worth an entire semester, unless you're interested in that.
 
  • #50
meBigGuy said:
NO NO NO. You ABSOLUTELY need to learn C before you learn C++ PERIOD.
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,
rcgldr said:
You can learn both at the same time...
 
  • #51
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,
No, it's not "like" C when you do that, it IS C.
 
  • #52
phinds said:
No, it's not "like" C when you do that, it IS C.
Impressive isn't it. It's two entirely different languages yet very much alike.
 
  • #53
Stephanus said:
Impressive isn't it. It's two entirely different languages yet very much alike.
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.
 
  • #54
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 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.
C developers thus have to keep its mainstream C alive while simultaneously developing C++ language. Almost all seniors understanding C also can code in C++ but the reverse case for the young people may not be true.
 
  • #55
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.
 
  • #56
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.
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.
 
  • #57
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.
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.
 
  • #58
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.
I consider overloading to be part of the OOP constructs.
 
  • #59
phinds said:
I consider overloading to be part of the OOP constructs.
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.
Although I use Delphi, but I'm very impressed with C++.
I don't have to write this, you must have known it, just to give you the idea.
In C++, we can write.
Vector + Vector = Vector
Vector - Vector = Vector
Coordinate + Vector = Coordinate
Matrix * Number = Matrix

and we can overrule these
Vector + Coordinate = n/a

I bet, Dennis Ritchie (?), when he developed C++ he must have thought that any programmer who wants to code in C++ must have sufficient knowledge in mathematic, logic as well as programming language.
 
  • #61
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.

For several years (roughly 1995-2003 IIRC), I taught a two-semester introductory college computer science course that used C++. I did not assume that students knew any C beforehand, or indeed any other programming language. Many other colleges and universities had similar courses. During this period, C++ was also the preferred language for AP computer science courses in US high schools.

Around 2005, the College Board changed the AP computer science course from C++ to Java, and many colleges and universities (including us) followed suit with their intro CS courses.

Even though there is less demand for them now, there are still some introductory C++ textbooks for such courses, for example:

https://www.amazon.com/dp/0133378713/?tag=pfamazon01-20

https://www.amazon.com/dp/0763771562/?tag=pfamazon01-20

I used this book which is no longer in print:

A Computer Science Tapestry: Exploring Computer Science with C++ (Astrachan)
 
Last edited by a moderator:
  • #62
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...
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).
 
  • #63
Stephanus said:
Sorry, it's Bjarne Stroustrup
https://en.wikipedia.org/wiki/C++
Who is Dennis Ritchie? I have his book.
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:
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...
 
  • #64
phinds said:
Stroustrup created C++ on top of C.

True. In fact, IIRC Stroustrup's working name for the language while he was developing it was "C with Classes."

That's why I keep saying that C++ is just C plus OOP stuff

At one time this was sort of true, to some approximation. I remember reading, while I was learning C++ around 1995, that there was some C code that most C++ compilers did not accept. I think there may have been an FAQ about in the Usenet newsgroup comp.lang.c++. My understanding is that after the first C++ standard came out in 1998(?) C and C++ started to diverge further from each other. Later versions of C added features which were not added to C++, and vice versa.
 
  • #65
Isn't it interesting. I bet all the mentors/staffs here are very capable and fluently coding in C or C++. But it seems that we argue what is C relative to C++.
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.
But C is an interesting P/L. Never do I find it in Pascal, assembly.
Much less Clipper :headbang:
 
  • #66
And for the OP question.
"Do I need to learn C before C++"
I think my answer is this.
If you don't know about OOP, then even if you compile your code by C++ compiler, then it's C, As @phinds says.
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?
 
  • #67
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).
To use operator overloading, you need OOP.
Function overloading does not need OOP.
And OOP does not depend whether the language can do function overloading or not.
C++ can have multiple inheritances, but C++ can't have two constructors without function overloading. Pascal/Delphi can have more than one constructors per class. But in my 20 years of Delphi programming, I never use two constructors.
 
  • #68
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 pretty sure Herb Schildt didn't include a compiler with any of his books.

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?
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.
 
  • #69
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.
It's been 20 years since I learn C++. I'm using C now. But I remembered something like "member function in union"
http://stackoverflow.com/questions/5275100/union-in-c-are-they-feasible
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)];
}
Yes, member function in enum really doesn't make any sense.
 
  • #70
Mark44 said:
...
You can have C structs with member functions -- by using function pointers.
No, it's not that we have a function pointer element in a struct. But it's a real method.
Remember, that class without methods works like struct. Just member variable.
But in struct, you can't derive it, you can't inherit it. And I'm pretty sure there are no virtual/dynamic method in struct. Frankly, I never used method in struct before. I just read in the C++ book, that it can do that. I only use class and played around with operator overloading.
 

Similar threads

Replies
9
Views
2K
Replies
29
Views
3K
Replies
10
Views
3K
Replies
6
Views
2K
Back
Top