LinuxQuestions.org
Visit Jeremy's Blog.
Home Forums Tutorials Articles Register
Go Back   LinuxQuestions.org > Forums > Non-*NIX Forums > Programming
User Name
Password
Programming This forum is for all programming questions.
The question does not have to be directly related to Linux and any language is fair game.

Notices


Reply
  Search this Thread
Old 05-16-2007, 06:51 AM   #1
noir911
Member
 
Registered: Apr 2004
Posts: 682

Rep: Reputation: Disabled
[C coding] reading code


I'm reading the Advanced Programming in Unix Environment to do system level coding. I know one way to learn coding is to read other people's code first. I looked at a few open source projects (written in C) but they all seem pretty daunting; I don't even know where to begin. There's no main.c or anything like that. I don't understand 95% of the codes & find the whole process confusing. However, I have learned to use gcc, lint, gdb very well.

Any suggestions would be much appreciated. Thanks.
 
Old 05-16-2007, 06:54 AM   #2
chrism01
LQ Guru
 
Registered: Aug 2004
Location: Sydney
Distribution: Rocky 9.2
Posts: 18,359

Rep: Reputation: 2751Reputation: 2751Reputation: 2751Reputation: 2751Reputation: 2751Reputation: 2751Reputation: 2751Reputation: 2751Reputation: 2751Reputation: 2751Reputation: 2751
This may seem a strange qn but it's not clear from your qn; how much C have you done ie written ie time / lines of code?
 
Old 05-16-2007, 07:04 AM   #3
bigearsbilly
Senior Member
 
Registered: Mar 2004
Location: england
Distribution: Mint, Armbian, NetBSD, Puppy, Raspbian
Posts: 3,515

Rep: Reputation: 239Reputation: 239Reputation: 239
personally, i find reading a wad of code not very useful at all until you know what you are doing. Otherwise as you say it's a muddle.
Have you got Kernighan and Ritchie?
http://en.wikipedia.org/wiki/The_C_P...anguage_(book)

The only way to learn is to do.

So i suggest you use the examples in your books
and fiddle about and experiment.
get used to using a debugger too so you can see what it all looks like.
ddd is a very nice debugging tool which works on top of native debuggers.

Last edited by bigearsbilly; 05-16-2007 at 07:08 AM.
 
Old 05-16-2007, 07:18 AM   #4
noir911
Member
 
Registered: Apr 2004
Posts: 682

Original Poster
Rep: Reputation: Disabled
Quote:
Originally Posted by chrism01
This may seem a strange qn but it's not clear from your qn; how much C have you done ie written ie time / lines of code?
Hi Chris

Over the years I have written approximately 1000 lines of C code. This includes basic hello world, structures, pointers, enums, #DEFINEs etc. etc. I have also learned how compilers work, gcc, ldd, linkers, gdb, make etc. along the way.
 
Old 05-16-2007, 07:20 AM   #5
noir911
Member
 
Registered: Apr 2004
Posts: 682

Original Poster
Rep: Reputation: Disabled
Quote:
Originally Posted by bigearsbilly
personally, i find reading a wad of code not very useful at all until you know what you are doing. Otherwise as you say it's a muddle.
Have you got Kernighan and Ritchie?
http://en.wikipedia.org/wiki/The_C_P...anguage_(book)

The only way to learn is to do.

So i suggest you use the examples in your books
and fiddle about and experiment.
get used to using a debugger too so you can see what it all looks like.
ddd is a very nice debugging tool which works on top of native debuggers.
Thanks. Yes. I bought K&R many moons ago and read bits and pieces from this book. I will definitely try to solve all the examples from this book and will also try out ddd.
 
Old 05-16-2007, 07:31 AM   #6
bigearsbilly
Senior Member
 
Registered: Mar 2004
Location: england
Distribution: Mint, Armbian, NetBSD, Puppy, Raspbian
Posts: 3,515

Rep: Reputation: 239Reputation: 239Reputation: 239
well you must remember, any non trivial project has had probably hundreds and hundreds of
man hours spent on it. Even superman couldn't grasp it in one sitting now could he?

allegedly linux has 60 million lines of code.
at one line a minute to read that's 11 years solid reading.

it's like being annoyed because you could not build the golden gate bridge on your own



edit: oops 6 million, so thats only a year to read then!!!

Last edited by bigearsbilly; 05-16-2007 at 07:34 AM.
 
Old 05-16-2007, 06:23 PM   #7
graemef
Senior Member
 
Registered: Nov 2005
Location: Hanoi
Distribution: Fedora 13, Ubuntu 10.04
Posts: 2,379

Rep: Reputation: 148Reputation: 148
Quote:
Originally Posted by bigearsbilly
edit: oops 6 million, so thats only a year to read then!!!
Bargain, cheap at twice the price.

You could take a small Open Source project, get it running and then start changing small parts of it. Whilst that is really just an academic exercise it will help you more than just reading the code. By small I mean small, you've written 1000 loc, so try and find something of that size. Maybe a linux command like cat would be a good starting point, having no idea how big it is, I could be wrong but I bet it's easier than grep
 
Old 05-17-2007, 08:05 PM   #8
bulliver
Senior Member
 
Registered: Nov 2002
Location: Edmonton AB, Canada
Distribution: Gentoo x86_64; Gentoo PPC; FreeBSD; OS X 10.9.4
Posts: 3,760
Blog Entries: 4

Rep: Reputation: 78
Quote:
Maybe a linux command like cat would be a good starting point, having no idea how big it is,
I tried going that route once. The problem is that all the coreutils share headers, functions and whatnot, so all the single command's code gets intermingled within. It is very frustrating to read, say, 'cat.c' and find it is fifteen lines long, and calls all its functional code from ~20 other files...

However, if you take the time to sort it out there is little doubt that it will educate you.

That said, I have personally rewritten a few of the coreutils from scratch in C as an educational exercise. So far I have uptime, free, cat, and rm.
 
  


Reply



Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is Off
HTML code is Off



Similar Threads
Thread Thread Starter Forum Replies Last Post
reading /proc throught C code knobby67 Programming 2 09-17-2006 07:16 AM
Reading Assembly code max_rsr Programming 4 07-22-2005 08:06 AM
some questions encounted during reading the source code qqrilxk Linux - Security 1 12-08-2004 09:23 PM
wma tag reading code captainfreedom Programming 1 07-21-2004 09:43 PM
reading kernel source code eshwar_ind Programming 4 06-02-2004 03:18 AM

LinuxQuestions.org > Forums > Non-*NIX Forums > Programming

All times are GMT -5. The time now is 07:43 PM.

Main Menu
Advertisement
My LQ
Write for LQ
LinuxQuestions.org is looking for people interested in writing Editorials, Articles, Reviews, and more. If you'd like to contribute content, let us know.
Main Menu
Syndicate
RSS1  Latest Threads
RSS1  LQ News
Twitter: @linuxquestions
Open Source Consulting | Domain Registration