Proper way to learn c ?

Discussion of chess software programming and technical issues.

Moderators: hgm, Rebel, chrisw

User avatar
Desperado
Posts: 879
Joined: Mon Dec 15, 2008 11:45 am

Re: Proper way to learn c ?

Post by Desperado »

Hi, Sven,

so here is my favourite :-)
http://esolangs.org/wiki/Ook!
ZirconiumX
Posts: 1334
Joined: Sun Jul 17, 2011 11:14 am

Re: Proper way to learn c ?

Post by ZirconiumX »

Desperado wrote:Hi, Sven,

so here is my favourite :-)
http://esolangs.org/wiki/Ook!
And you haven't noticed SQRT???

I *do* wonder who created that.

Matthew:out
Some believe in the almighty dollar.

I believe in the almighty printf statement.
syzygy
Posts: 5566
Joined: Tue Feb 28, 2012 11:56 pm

Re: Proper way to learn c ?

Post by syzygy »

Sven Schüle wrote:
mar wrote:Huh. C++ is a superset of C. So I really don't see why Torvalds wanted to rewrite the kernel in C++,
that's completely stupid as it would break existing C programs. :shock:
I see two reasons why that "C++ rewrite" of the Linux kernel failed:

1) You cannot simply "rewrite" something as complex as an OS kernel in C++ unless you also redesign it. A procedural-style software of that magnitude will remain procedural even if you introduce some classes, inheritance, something here and something there. I don't say that Linus made no attempt of a redesign but at least "rewriting in C++" does not suggest to me he did so.
According to this source, it was not a redesign, but just an effort to get it to compile with g++ (presumably to allow certain C++ features to be used):
In the dark old days, in the time that most of you hadn't even heard of the word "Linux", the kernel was once modified to be compiled under g++. That lasted for a few revisions. People complained about the performance drop. It turned out that compiling a piece of C code with g++ would give you worse code. It shouldn't have made a difference, but it did. Been there, done that.
mar wrote:Huh. C++ is a superset of C. So I really don't see why Torvalds wanted to rewrite the kernel in C++,
that's completely stupid as it would break existing C programs. :shock:
I don't see why a kernel written in C++ could not run existing C programs.
mar
Posts: 2555
Joined: Fri Nov 26, 2010 2:00 pm
Location: Czech Republic
Full name: Martin Sedlak

Re: Proper way to learn c ?

Post by mar »

syzygy wrote: I don't see why a kernel written in C++ could not run existing C programs.
Name mangling being reason #1 (overloading). There's more, much more :wink:
EDIT: Absolutely agree with Sven and Daniel.
Last edited by mar on Wed Jul 11, 2012 1:30 am, edited 1 time in total.
mar
Posts: 2555
Joined: Fri Nov 26, 2010 2:00 pm
Location: Czech Republic
Full name: Martin Sedlak

Re: Proper way to learn c ?

Post by mar »

Desperado wrote:Hi, Sven,

so here is my favourite :-)
http://esolangs.org/wiki/Ook!
Reminds me of brainfuck :wink:
EDIT: uh ok, got it
syzygy
Posts: 5566
Joined: Tue Feb 28, 2012 11:56 pm

Re: Proper way to learn c ?

Post by syzygy »

mar wrote:
syzygy wrote:I don't see why a kernel written in C++ could not run existing C programs.
Name mangling being reason #1 (overloading). There's more, much more :wink:
Do you realise that Linux executables are not linked against kernel object code?

Name mangling is not an issue here at all.
mar
Posts: 2555
Joined: Fri Nov 26, 2010 2:00 pm
Location: Czech Republic
Full name: Martin Sedlak

Re: Proper way to learn c ?

Post by mar »

syzygy wrote: Do you realise that Linux executables are not linked against kernel object code?

Name mangling is not an issue here at all.
No I don't :) Against CRT then? So all you have to do is use extern "C" :)
Cool. Very C++ish
syzygy
Posts: 5566
Joined: Tue Feb 28, 2012 11:56 pm

Re: Proper way to learn c ?

Post by syzygy »

mar wrote:
syzygy wrote: Do you realise that Linux executables are not linked against kernel object code?

Name mangling is not an issue here at all.
No I don't :) Against CRT then? So all you have to do is use extern "C" :)
Cool. Very C++ish
Huh? Do you know what the Linux kernel is? It is not the C library....
mar
Posts: 2555
Joined: Fri Nov 26, 2010 2:00 pm
Location: Czech Republic
Full name: Martin Sedlak

Re: Proper way to learn c ?

Post by mar »

syzygy wrote:Huh? Do you know what the Linux kernel is? It is not the C library....
You tell me. You don't link against kernel directly. You don't link against CRT. That sounds like magic :D
EDIT: how do you open a file then? You leave an email to Linus?
syzygy
Posts: 5566
Joined: Tue Feb 28, 2012 11:56 pm

Re: Proper way to learn c ?

Post by syzygy »

mar wrote:
syzygy wrote:Huh? Do you know what the Linux kernel is? It is not the C library....
You tell me. You don't link against kernel directly. You don't link against CRT. That sounds like magic :D
EDIT: how do you open a file then? You leave an email to Linus?
No, the normal way is to link against glibc, which will then invoke the kernel using a system call. Making a system call can only be implemented in assembly and you will not notice any difference between C and C++ there.