Page 1 of 1

Learning C

Posted: Tue May 20, 2014 8:09 am
by Reasonable
Are there any good resources for learning C for Raspberry Pi? Any good book recommendations? I'm not a complete novice and understand the basics but never really dealt with C. I did some work with C++ but a very long time ago.

I've been looking at some tutorials and they are either along the lines of "hello world" or have hundreds lines of code with little explanation.

Re: Learning C

Posted: Tue May 20, 2014 8:28 am
by AndyD
Assuming that you are using Raspbian, then any tutorial aimed at C programming on Linux should be applicable. I learned C a long time ago (1991), so I can't recommend any particular modern books or resources. I used the venerable book The C Programming Language by Kernighan and RItchie. If you already know some C++, then you have some knowledge of C as well. They have a lot in common. In fact most C programs will compile and run (correctly) using the C++ compiler.

Re: Learning C

Posted: Tue May 20, 2014 8:32 am
by ShiftPlusOne
+1 for K&R

Then I recommend playing around with C and SDL.

Re: Learning C

Posted: Wed May 21, 2014 2:38 am
by Conrad Goodwin
+1 more for K&R. I'm working on it now, and think it's a dandy.

Re: Learning C

Posted: Wed May 21, 2014 8:10 am
by jamesh
Only problem with K&R is the bracketing style. It's partly responsible for the Linux kernel coding style, which is evil...

Re: Learning C

Posted: Wed May 21, 2014 9:23 am
by DougieLawson
jamesh wrote:Only problem with K&R is the bracketing style. It's partly responsible for the Linux kernel coding style, which is evil...
So why do you use it in the picamera code? Isn't 1TBS better?

Re: Learning C

Posted: Wed May 21, 2014 9:50 am
by jamesh
DougieLawson wrote:
jamesh wrote:Only problem with K&R is the bracketing style. It's partly responsible for the Linux kernel coding style, which is evil...
So why do you use it in the picamera code? Isn't 1TBS better?
I don't. K&R uses 1TBS (well, 1TBS is a slight modificaiton of K&R), I'm an Allman fan. Raspistill/Vid uses Allman.

Re: Learning C

Posted: Wed May 21, 2014 11:11 am
by ShiftPlusOne
What's wrong with 1TBS?

I started with Allman, since that's what the first C book I read used. I ended up switching to GNU and then settling on 1TBS since it seems to use space better, while retaining readability.

Re: Learning C

Posted: Wed May 21, 2014 12:29 pm
by tenspot
Hi,

I found the following resource useful for getting started with C.

http://cslibrary.stanford.edu/101/EssentialC.pdf

Re: Learning C

Posted: Wed May 21, 2014 12:43 pm
by PeterO
AndyD wrote: I used the venerable book The C Programming Language by Kernighan and RItchie.
But did you use the 1st Edition ? ;)
PeterO

Re: Learning C

Posted: Wed May 21, 2014 2:01 pm
by AndyD
PeterO wrote:
AndyD wrote: I used the venerable book The C Programming Language by Kernighan and RItchie.
But did you use the 1st Edition ? ;)
PeterO
No, the second edition is Copyright 1988. I started programming in C in 1991.
tenspot wrote:Hi,

I found the following resource useful for getting started with C.

http://cslibrary.stanford.edu/101/EssentialC.pdf
From a very brief look, there appears to be some very good information in that PDF.

Re: Learning C

Posted: Wed May 21, 2014 2:13 pm
by Richard-TX
Learning any computer language is just like learning German, Italian, etc. It has it's own dictionary, grammar, and punctuation rules. In the very early days, when a person took a computer programming course ion college, the credits earned were under the heading of "Foreign Language" which is a fair assessment.

If you really want to learn about C, go talk to some college students. Some of the most brilliant programming I have ever seen came from 3rd year students.

Re: Learning C

Posted: Wed May 21, 2014 7:45 pm
by williamhbell
Reasonable wrote:Are there any good resources for learning C for Raspberry Pi?
You could always try the C Cave series in The MagPi. The list of articles can be found by going to
http://magpiindex.steverigg.co.uk/index.php
and then selecting "Programming C/C++" from the category menu. The articles build from simple to complete concepts, in stages. All articles have working source code examples and problems to solve.

Kernighan and Ritchie's book is well worth having. However, it does not cover the non ANSI libraries that can be very useful on Linux. Some non-ANSI features are introduced in the C Cave, but these are highlighted as being such.

Re: Learning C

Posted: Wed May 21, 2014 10:07 pm
by AndyD
williamhbell wrote:...
Kernighan and Ritchie's book is well worth having. However, it does not cover the non ANSI libraries that can be very useful on Linux. ...
Last century ( :) ) I used the book Advanced Programming in the UNIX Environment by the late W. Richard Stevens, as it covered a number of UNIX implementation details. There is a newer (3rd) edition published in 2013. However, the Internet is now a very useful resource.