Reasonable
Posts: 49
Joined: Sun Apr 20, 2014 8:12 pm

Learning C

Tue May 20, 2014 8:09 am

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.

User avatar
AndyD
Posts: 2331
Joined: Sat Jan 21, 2012 8:13 am
Location: Melbourne, Australia
Contact: Website

Re: Learning C

Tue May 20, 2014 8:28 am

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.

ShiftPlusOne
Raspberry Pi Engineer & Forum Moderator
Raspberry Pi Engineer & Forum Moderator
Posts: 5963
Joined: Fri Jul 29, 2011 5:36 pm
Location: The unfashionable end of the western spiral arm of the Galaxy

Re: Learning C

Tue May 20, 2014 8:32 am

+1 for K&R

Then I recommend playing around with C and SDL.

Conrad Goodwin
Posts: 8
Joined: Fri May 09, 2014 3:23 am
Location: Puerto Octay, X Region, Chile SA

Re: Learning C

Wed May 21, 2014 2:38 am

+1 more for K&R. I'm working on it now, and think it's a dandy.

jamesh
Raspberry Pi Engineer & Forum Moderator
Raspberry Pi Engineer & Forum Moderator
Posts: 23659
Joined: Sat Jul 30, 2011 7:41 pm

Re: Learning C

Wed May 21, 2014 8:10 am

Only problem with K&R is the bracketing style. It's partly responsible for the Linux kernel coding style, which is evil...
Principal Software Engineer at Raspberry Pi (Trading) Ltd.
Contrary to popular belief, humorous signatures are allowed. Here's an example...
"My grief counseller just died, luckily, he was so good, I didn't care."

User avatar
DougieLawson
Posts: 36116
Joined: Sun Jun 16, 2013 11:19 pm
Location: Basingstoke, UK
Contact: Website Twitter

Re: Learning C

Wed May 21, 2014 9:23 am

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?
Note: Having anything humorous in your signature is completely banned on this forum. Wear a tin-foil hat and you'll get a ban.

Any DMs sent on Twitter will be answered next month.

This is a doctor free zone.

jamesh
Raspberry Pi Engineer & Forum Moderator
Raspberry Pi Engineer & Forum Moderator
Posts: 23659
Joined: Sat Jul 30, 2011 7:41 pm

Re: Learning C

Wed May 21, 2014 9:50 am

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.
Principal Software Engineer at Raspberry Pi (Trading) Ltd.
Contrary to popular belief, humorous signatures are allowed. Here's an example...
"My grief counseller just died, luckily, he was so good, I didn't care."

ShiftPlusOne
Raspberry Pi Engineer & Forum Moderator
Raspberry Pi Engineer & Forum Moderator
Posts: 5963
Joined: Fri Jul 29, 2011 5:36 pm
Location: The unfashionable end of the western spiral arm of the Galaxy

Re: Learning C

Wed May 21, 2014 11:11 am

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.

tenspot
Posts: 4
Joined: Sun Jun 03, 2012 2:15 pm

Re: Learning C

Wed May 21, 2014 12:29 pm

Hi,

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

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

User avatar
PeterO
Posts: 5005
Joined: Sun Jul 22, 2012 4:14 pm

Re: Learning C

Wed May 21, 2014 12:43 pm

AndyD wrote: I used the venerable book The C Programming Language by Kernighan and RItchie.
But did you use the 1st Edition ? ;)
PeterO
Discoverer of the PI2 XENON DEATH FLASH!
Interests: C,Python,PIC,Electronics,Ham Radio (G0DZB),1960s British Computers.
"The primary requirement (as we've always seen in your examples) is that the code is readable. " Dougie Lawson

User avatar
AndyD
Posts: 2331
Joined: Sat Jan 21, 2012 8:13 am
Location: Melbourne, Australia
Contact: Website

Re: Learning C

Wed May 21, 2014 2:01 pm

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.

User avatar
Richard-TX
Posts: 1549
Joined: Tue May 28, 2013 3:24 pm
Location: North Texas

Re: Learning C

Wed May 21, 2014 2:13 pm

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.
Richard
Doing Unix since 1985.
The 9-25-2013 image of Wheezy can be found at:
http://downloads.raspberrypi.org/raspbian/images/raspbian-2013-09-27/2013-09-25-wheezy-raspbian.zip

User avatar
williamhbell
Posts: 291
Joined: Mon Dec 26, 2011 5:13 pm
Contact: Website Twitter

Re: Learning C

Wed May 21, 2014 7:45 pm

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.

User avatar
AndyD
Posts: 2331
Joined: Sat Jan 21, 2012 8:13 am
Location: Melbourne, Australia
Contact: Website

Re: Learning C

Wed May 21, 2014 10:07 pm

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.

Return to “C/C++”