Page 2 of 4

Re: learning c/c++

Posted: Thu Apr 04, 2013 3:26 am
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.

Re: learning c/c++

Posted: Thu Apr 04, 2013 4:51 am
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 ;)

Re: learning c/c++

Posted: Thu Apr 04, 2013 8:08 am
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++.

Re: learning c/c++

Posted: Thu Apr 04, 2013 9:16 am
by Mikemk
I'm going to try using this tutorial:
http://www.cprogramming.com/tutorial/c/lesson1.html

Re: learning c/c++

Posted: Thu Apr 04, 2013 9:39 am
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

Re: learning c/c++

Posted: Thu Apr 04, 2013 9:54 am
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.

Re: learning c/c++

Posted: Thu Apr 04, 2013 10:53 am
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

Re: learning c/c++

Posted: Thu Apr 04, 2013 11:01 am
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

Re: learning c/c++

Posted: Thu Apr 04, 2013 11:52 am
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.

Re: learning c/c++

Posted: Thu Apr 04, 2013 12:23 pm
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. :)

Re: learning c/c++

Posted: Thu Apr 04, 2013 12:30 pm
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.....

Re: learning c/c++

Posted: Thu Apr 04, 2013 12:38 pm
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?

Re: learning c/c++

Posted: Thu Apr 04, 2013 2:58 pm
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.

Re: learning c/c++

Posted: Thu Apr 04, 2013 4:29 pm
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.

Re: learning c/c++

Posted: Thu Apr 04, 2013 5:53 pm
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.