learning c/c++

Programming, for all ages and all languages.
Antti
Member
Member
Posts: 923
Joined: Thu Jul 05, 2012 5:12 am
Location: Finland

Re: learning c/c++

Post by Antti »

I have written some small applications in C++ but I am not very familiar with it. I have a feeling that the general opinion seems to be against C++ when it comes to low-level programming. For beginners how do not know yet, there is a famous "C++ is a horrible language" email by Linus Torvalds. Linus wrote aggressively and tongue-in-cheek as usual but the email contains some valid points that I understand. However, I am not so expert that I could plausibly say whether C++ is that bad or not. I am not against high-level languages. However, I think that C++ tries to be high and low at the same time without being very good at either side. It seems not very elegant.

Why I use just C? It allows me to do programming in a procedural paradigm without feeling any guilty of misusing the programming language. I simply cannot write elegant object-oriented C++ code. First I thought I should use an assembly language as much as possible but then I realised that C code is quite easy to "read as assembly." I feel that I have a quite good control of what is happening when using C. I also feel that the tool chain for building the OS is a little thinner. Of course C compilers (gcc) are very complicated anyway, but still...

Is your assumed "avoidance of C++" based on facts? I admit that mine is not.
User avatar
Griwes
Member
Member
Posts: 374
Joined: Sat Jul 30, 2011 10:07 am
Libera.chat IRC: Griwes
Location: Wrocław/Racibórz, Poland
Contact:

Re: learning c/c++

Post by Griwes »

From what I have observed, people usually avoid C++, because they learned C, C# or Java first and try to write C, C# or Java in C++, then fail completely and blame the language, instead of learning it properly ;)
Reaver Project :: Repository :: Ohloh project page
<klange> This is a horror story about what happens when you need a hammer and all you have is the skulls of the damned.
<drake1> as long as the lock is read and modified by atomic operations
User avatar
trinopoty
Member
Member
Posts: 87
Joined: Wed Feb 09, 2011 2:21 am
Location: Raipur, India

Re: learning c/c++

Post by trinopoty »

I use a mix of C and C++. I don't think C++ is all that bad for application programming. When it comes to system programming however, things are a bit different.
The main reason I use C++ is because it reduces name collisions and makes my code more organized.
Of course, I have become used to using C and C++ together, it has become a bit difficult for me to write code in pure C++.
Always give a difficult task to a lazy person. He will find an easy way to do it.
Mikemk
Member
Member
Posts: 409
Joined: Sat Oct 22, 2011 12:27 pm

Re: learning c/c++

Post by Mikemk »

I'm going to try using this tutorial:
http://www.cprogramming.com/tutorial/c/lesson1.html
Programming is 80% Math, 20% Grammar, and 10% Creativity <--- Do not make fun of my joke!
If you're new, check this out.
Opcode
Member
Member
Posts: 29
Joined: Mon Apr 01, 2013 2:50 pm

Re: learning c/c++

Post by Opcode »

m12 wrote:PS, I already know java and C#, so...
I suggest grabbing a copy of http://en.wikipedia.org/wiki/The_C_Programming_Language. Great book!

I would personally stay away from any object oriented language as it's just a plain mess. If you already know assembly/C#/java then C is pretty much the same. In fact the C language is pretty intuitive. If you know how to program in those other languages you mentioned then I am going to take that as a sign that you know how to program. C is the medium in which you'll be implementing your programming ability. Anyway, grab that book above and you'll be good. Just remember you can't really use any standard C functions when OSDev'n unless you write versions for your own system. Other areas of research that you'll need include 1) Interfacing C and Assembly 2) C calling conventions 3) Getting the compiler/linker to organize the output the way you want
Mikemk
Member
Member
Posts: 409
Joined: Sat Oct 22, 2011 12:27 pm

Re: learning c/c++

Post by Mikemk »

@Opcode Thank you for the information. I can't take a look at that book because the only internet I have access to has a content filter blocking wikipedia, but I can google for the information.
Programming is 80% Math, 20% Grammar, and 10% Creativity <--- Do not make fun of my joke!
If you're new, check this out.
User avatar
AJ
Member
Member
Posts: 2646
Joined: Sun Oct 22, 2006 7:01 am
Location: Devon, UK
Contact:

Re: learning c/c++

Post by AJ »

Hi,
Opcode wrote:I would personally stay away from any object oriented language as it's just a plain mess.
BS. OO languages are not more messy by nature than procedural languages if used correctly. A lot of it is personal preference and using the right paradigm for the right task.
If you already know assembly/C#/java then C is pretty much the same.
OO languages are "just a plain mess". C# and Java are OO. C "is pretty much the same", therefore C is "pretty much just a plain mess"?

I would also dispute the fact that C is anything like C# or Java. Maybe your difficulty with OO languages is that you try to program with them in the same way you would program in C?

Cheers,
Adam
shikhin
Member
Member
Posts: 274
Joined: Sat Oct 09, 2010 3:35 am
Libera.chat IRC: shikhin
Contact:

Re: learning c/c++

Post by shikhin »

Hi,

Tooltip (to everyone): let's avoid bringing in personal opinions. They are simply not required. The OP specifically asked what he needed to do to rewrite the kernel in C++. Saying something like "learn C first, because it is easier to map ASM to C; learn C++ after that, but try to unlearn most of the stuff you learnt from C" is fine. Saying something like "in my personal opinion, OO isn't good," on the other hand, isn't.

Tooltip (to OP): our Wiki effectively explains how to use C++ for the kernel. Several other websites explain how to learn C++. I somehow doubt the fact that you're smart enough to write "multi-thousand line files" in assembly, but you can't use Google properly...

Regards,
Shikhin
http://shikhin.in/

Current status: Gandr.
Mikemk
Member
Member
Posts: 409
Joined: Sat Oct 22, 2011 12:27 pm

Re: learning c/c++

Post by Mikemk »

Shikhin wrote:I somehow doubt the fact that you're smart enough to write "multi-thousand line files" in assembly, but you can't use Google properly...
I have a few things to say here.
Firstly, creating something yourself (my kernel) is different from looking to buy something (googling) Additionally, creating it out of play doh (assembly) is different from using legos (C/c++). play doh is easier, but doesn't have the organization present from using legos.
Secondly, why do you think I can't use google? This thread is to get the information that I'm googling for. If I asked you to build me an airplane and you have no clue how an airplane works, would you automatically look into purchasing an aileron? No, you'd first want to find out how to build an airplane, then look into buying or building the parts.

BTW, an aileron is used to turn a plane. Rather, 2 ailerons.
Programming is 80% Math, 20% Grammar, and 10% Creativity <--- Do not make fun of my joke!
If you're new, check this out.
shikhin
Member
Member
Posts: 274
Joined: Sat Oct 09, 2010 3:35 am
Libera.chat IRC: shikhin
Contact:

Re: learning c/c++

Post by shikhin »

Hi,
m12 wrote:Firstly, creating something yourself (my kernel) is different from looking to buy something (googling) Additionally, creating it out of play doh (assembly) is different from using legos (C/c++). play doh is easier, but doesn't have the organization present from using legos.
Sadly, I don't see any analogy holding in there. What I do understand is the fact that you want to get information on how to learn C++, and use it for kernel dev. The wiki exists to document that (and it does document it), and furthermore, you can Google it up to find that information. I don't see how you don't know what to Google for.
m12 wrote:Secondly, why do you think I can't use google? This thread is to get the information that I'm googling for. If I asked you to build me an airplane and you have no clue how an airplane works, would you automatically look into purchasing an aileron? No, you'd first want to find out how to build an airplane, then look into buying or building the parts.
If you asked me to build an aeroplane, I'd go: Aeroplane, parts of an Aeroplane, how to build an aeroplane.
m12 wrote:BTW, an aileron is used to turn a plane. Rather, 2 ailerons.
Aileron.

Regards,
Shikhin

P.S. Alert me if I sound too harsh. You really can't get real emotions across forum boards. :)
http://shikhin.in/

Current status: Gandr.
Opcode
Member
Member
Posts: 29
Joined: Mon Apr 01, 2013 2:50 pm

Re: learning c/c++

Post by Opcode »

AJ wrote:Hi,
Opcode wrote:I would personally stay away from any object oriented language as it's just a plain mess.
BS. OO languages are not more messy by nature than procedural languages if used correctly. A lot of it is personal preference and using the right paradigm for the right task.
If you already know assembly/C#/java then C is pretty much the same.
OO languages are "just a plain mess". C# and Java are OO. C "is pretty much the same", therefore C is "pretty much just a plain mess"?

I would also dispute the fact that C is anything like C# or Java. Maybe your difficulty with OO languages is that you try to program with them in the same way you would program in C?

Cheers,
Adam
Question: Which one is a) Java b) C# c) C d) BASIC ?

1) for(i = 0; i < 10; i++);
2) int i = 0;
3) return;
4) DIM A as INTEGER

Also, I don't recall having difficulty doing OO. You're just assuming. Fact is I've done lots of projects using OO. If this was a 3D engine forum for instance I would be all for it.

I was referring to OO as a mess with regards to debugging and such. Was merely trying to save this forum from posts on such topics as "What's a vtable?"

And to the original poster:

I did misread your first post. I thought I was a "how can I do this in C or C++" when in fact it was "how can I do this in C++." Well, the good news is, like I mentioned before, then language is pretty similar to what you know. My Java extent is limited to college (never did get on that train) and C# was also limited to just playing around with it in visual studio when it came out but I do know this: syntax is very very similar. You'll have no problem migrating. I also assume since you come from Java/C# background you have an understanding of the various design patterns used to solve problem sets. Once again, you will eventually need to do research on C++ internals to see how the behind the scenes magic happens.

If you have any questions, please feel free to ask Aj as I have difficulties with OO. Who knows, maybe Shikhin can provide you with a tasty Google link or two. Anyway, off to my multi-million line .asm file.....
Opcode
Member
Member
Posts: 29
Joined: Mon Apr 01, 2013 2:50 pm

Re: learning c/c++

Post by Opcode »

m12 wrote:BTW, an aileron is used to turn a plane. Rather, 2 ailerons.
And one rudder to stop those two ailerons from turning the plane. :mrgreen:

You a pilot too?
User avatar
Griwes
Member
Member
Posts: 374
Joined: Sat Jul 30, 2011 10:07 am
Libera.chat IRC: Griwes
Location: Wrocław/Racibórz, Poland
Contact:

Re: learning c/c++

Post by Griwes »

Opcode, you cannot compare single statements when comparing languages, you have to compare styles and practices. Syntax does not make a language - if I felt I need to, I'd be able to abuse C syntax and write C++ in it. But it wouldn't be C; it would be almost-C++.

Java and C# have much in common, although they are totally different. C, C++, C# and Java have only one thing in common - pretty similar syntax. But they are totally different languages, each with own practices and style.

Plus, what is a vtable? It's merely an implementation detail.
Last edited by Griwes on Fri Apr 05, 2013 12:00 am, edited 1 time in total.
Reaver Project :: Repository :: Ohloh project page
<klange> This is a horror story about what happens when you need a hammer and all you have is the skulls of the damned.
<drake1> as long as the lock is read and modified by atomic operations
Opcode
Member
Member
Posts: 29
Joined: Mon Apr 01, 2013 2:50 pm

Re: learning c/c++

Post by Opcode »

Griwes wrote:Opcode, you cannot compare single statements when comparing languages, you have to compare styles and practices. Syntax does not make a language - if I felt I need to, I'd be able to abuse C syntax and write C++ in it. But it wouldn't be C; it would be almost-C++.

Java and C# have much in common, although they are totally different. C, C++, C# and Java have only one thing in common - pretty similar syntax. But they are totally different languages, each with own practices and style.
My whole point is that the syntax is pretty much the same. Prior knowledge in assembly = procedural brain. Prior knowledge in C#/Java = OO brain with bonus skillup points in C/C++syntax.
Griwes wrote:Plus, what I vtable?
That's not even a sentence.
User avatar
Kazinsal
Member
Member
Posts: 559
Joined: Wed Jul 13, 2011 7:38 pm
Libera.chat IRC: Kazinsal
Location: Vancouver
Contact:

Re: learning c/c++

Post by Kazinsal »

m12 wrote:@Opcode Thank you for the information. I can't take a look at that book because the only internet I have access to has a content filter blocking wikipedia, but I can google for the information.
http://pelusa.fis.cinvestav.mx/tmatos/L ... nguage.pdf

If you can't access that through the filter, lemme know and I can send it to you through some form of file transfer.
Post Reply