Note that there are some explanatory texts on larger screens.

plurals
  1. PO
    text
    copied!<p><a href="https://stackoverflow.com/questions/236838/what-are-good-linux-unix-books-for-an-advancing-user/236967#236967">This posting</a> has a list of unix books which includes most of the classic C/Unix works. For C programming on Windows, Petzold's <a href="http://rads.stackoverflow.com/amzn/click/157231995X" rel="nofollow noreferrer">Programming Windows</a> is probably the best start.</p> <p>For C program design, some of the unix programming books will tell you snippets but I'm not aware of a 'C program architecture' book.</p> <p>If you're used to java, some tips for C programing are:</p> <ol> <li><p><a href="https://stackoverflow.com/questions/161053/c-which-is-faster-stack-allocation-or-heap-allocation">Make</a> <a href="https://stackoverflow.com/questions/685601/about-c-c-stack-allocation">use</a> <a href="http://www.math.cam.ac.uk/undergrad/catam/ccatsl/manual/node50.html" rel="nofollow noreferrer">of</a> <a href="https://stackoverflow.com/questions/79923/what-and-where-are-the-stack-and-heap">stack</a>. Often when you call a procedure you will want to have variables allocated in the caller's stack frame and pass pointers to them into the procedure you want to call. This will be substantially faster than dynamically allocating memory with <a href="http://en.wikipedia.org/wiki/Malloc" rel="nofollow noreferrer"><code>malloc()</code></a> and much less error prone. Do this wherever appropriate.</p></li> <li><p>C doesn't do <a href="http://en.wikipedia.org/wiki/Garbage_collection_%28computer_science%29" rel="nofollow noreferrer">garbage collection,</a> so dynamically allocating data items is more fiddly and you have to keep track of them to <a href="http://en.wikipedia.org/wiki/Memory_leak" rel="nofollow noreferrer">make sure they get freed.</a> Variables allocated on the stack (see 1) are more 'idiomatic' where they are applicable. Plus, you don't have to free them - this is a bonus for local variables.</p></li> <li><p>Apropos of (2), consider an architecture where your functions return a status or error code and pass data in and out using the stack as per (1).</p></li> <li><p>Get to know what <a href="http://en.wikipedia.org/wiki/Setjmp" rel="nofollow noreferrer"><code>setjmp()</code></a> and <a href="http://en.wikipedia.org/wiki/Setjmp" rel="nofollow noreferrer"><code>longjmp()</code></a> do. They can be quite useful for generic error handler mechanisms in lieu of structured exception handling functionality.</p></li> <li><p><a href="http://en.wikibooks.org/wiki/C_Programming/Error_handling" rel="nofollow noreferrer">C does not support exceptions.</a> See (3).</p></li> <li><p><a href="http://en.wikipedia.org/wiki/Lint_%28software%29" rel="nofollow noreferrer">Lint</a> is your friend. <a href="http://www.splint.org/" rel="nofollow noreferrer">Splint</a> is even friendlier.</p></li> <li><p>Learn what the <a href="http://en.wikipedia.org/wiki/C_preprocessor" rel="nofollow noreferrer">preprocessor</a> does and what you shouldn't do with it even if you can.</p></li> <li><p>Learn the ins and outs of <a href="http://en.wikipedia.org/wiki/Endianness" rel="nofollow noreferrer">endian-ness</a>, <a href="http://www.cs.umd.edu/class/spring2003/cmsc311/Notes/Data/aligned.html" rel="nofollow noreferrer">word alignment</a>, <a href="http://www.eskimo.com/~scs/cclass/notes/sx10b.html" rel="nofollow noreferrer">pointer arithmetic</a> and other low-level architectural arcana. Contrary to popular opinion these are not rocket science. If you're feeling keen, try dabbling in assembly language and get a working knowledge of that. It will do much for your understanding of what's going on in your C program.</p></li> <li><p>C has no concept of module scope, so plan your use of includes, prototype declarations, and use of <a href="https://stackoverflow.com/questions/2753962/what-does-the-extern-keyword-mean"><code>extern</code></a> and <a href="http://blog.robbychen.com/2010/09/26/the-c-static-keyword/" rel="nofollow noreferrer"><code>static</code></a> to make private scopes and import identifiers.</p></li> <li><p>GUI programming in C is tedious on <a href="http://www.winprog.org/tutorial/" rel="nofollow noreferrer">all</a> <a href="http://tronche.com/gui/x/xlib/introduction/" rel="nofollow noreferrer">platforms.</a></p></li> <li><p>Apropos of (10) learn the C API of at least one scripting language such as <a href="http://wiki.tcl.tk/11541" rel="nofollow noreferrer">Tcl</a>, <a href="http://www.lua.org/pil/24.html" rel="nofollow noreferrer">Lua</a> or <a href="http://docs.python.org/extending/index.html#extending-index" rel="nofollow noreferrer">Python.</a> In many cases the best use of C is as a core high-performance engine on an application that is substantially written in something else.</p></li> <li><p>The equivalent of a constructor is an initialising function where you pass in a pointer to the item you want set up. Often you can see this in the form of a call to the function that looks like <code>setup_foo(&amp;my_foo)</code>. It's better to separate allocation from initialising, as you can use this function to initialise an item you have allocated on the stack. A similar principle applies to destructors.</p></li> <li><p>Most people find <a href="http://en.wikipedia.org/wiki/Hungarian_notation" rel="nofollow noreferrer">Hungarian notation</a> about as readable as written Hungarian. The exception to this is native Hungarian speakers, who typically find Hungarian notation about as legible as <a href="http://www.google.co.uk/images?hl=en&amp;expIds=17259,27491,27586,27812,27817&amp;xhr=t&amp;q=cuneiform&amp;cp=4&amp;client=firefox-a&amp;hs=kwg&amp;rls=org.mozilla:en-GB:official&amp;um=1&amp;ie=UTF-8&amp;source=univ&amp;ei=c37zTP-5Lo-1hAeIwenDCQ&amp;sa=X&amp;oi=image_result_group&amp;ct=title&amp;resnum=4&amp;sqi=2&amp;ved=0CEMQsAQwAw&amp;biw=1200&amp;bih=815" rel="nofollow noreferrer">Cuneiform.</a>. Unfortunately Hungarian notation is widely encounterd in Windows software and the entire Win32 API uses it, with the expected effects on the legibility of software written on this platform.</p></li> <li><p>C/Unix books, even really good ones like the ones written by the late W Richard Stevens tend to be available secondhand quite cheaply through Amazon marketplace. In no particular order, get a copy of <a href="http://en.wikipedia.org/wiki/The_C_Programming_Language_%28book%29" rel="nofollow noreferrer">K&amp;R,</a> Stevens <a href="http://www.kohala.com/start/apue.html" rel="nofollow noreferrer">APUE</a> and <a href="http://www.kohala.com/start/unpv12e.html" rel="nofollow noreferrer">UNP 1</a> <a href="http://www.kohala.com/start/unpv22e/unpv22e.html" rel="nofollow noreferrer">&amp; 2,</a> the <a href="http://en.wikipedia.org/wiki/Principles_of_Compiler_Design" rel="nofollow noreferrer">Dragon book,</a> <a href="http://www.informit.com/authors/bio.aspx?a=AFAC0A13-A141-47D6-B508-04A03D7B4634" rel="nofollow noreferrer">Rochkind,</a> <a href="http://www.cs.bell-labs.com/cm/cs/pearls/" rel="nofollow noreferrer">Programming Pearls,</a> <a href="http://www.charlespetzold.com/pw5/index.html" rel="nofollow noreferrer">Petzold</a> and <a href="http://rads.stackoverflow.com/amzn/click/0735607532" rel="nofollow noreferrer">Richter</a> (if working on Windows) and any of the other classic C/Unix works. Read, scribble on them with a pencil and generally interact with the books.</p></li> <li><p>There are many, many good <a href="http://www.google.co.uk/search?q=c+programming" rel="nofollow noreferrer">C/Unix programming</a> resources on the web.</p></li> <li><p>Read and understand the <a href="http://www.lysator.liu.se/c/ten-commandments.html" rel="nofollow noreferrer">Ten Commandments of C Programming</a> and some of the meta discussion as to the why's and wherefores behind the commandments. This is showing its age to a certain extent, although most of it is still relevant and obscure compilers are still <a href="https://stackoverflow.com/questions/243387/best-language-for-safety-critical-software/243573#243573">quite common in the embedded systems world</a>.</p></li> <li><p><a href="http://dinosaur.compilertools.net/" rel="nofollow noreferrer">Lex and Yacc</a> are your friend if you want to write parsers.</p></li> <li><p>As Navicore <a href="https://stackoverflow.com/questions/925754/resources-for-learning-c-program-design/928786#928786">points out below (+1)</a>, Hanson's <a href="http://www.cs.princeton.edu/software/cii/" rel="nofollow noreferrer">'C Interfaces and Implementations'</a> is a run-down on interface/implementation design for modular architecture with a bunch of examples. I have actually heard of this book and heard good things about it, although I can't claim to have read it. Aside from the C idioms that I've described above, this concept is arguably the core of good procedural design. In fact, other procedural languages such as Modula-2 actually make this concept explicit in their design. This might be the closest thing to a 'C Program Architecture' book in print.</p></li> <li><p>Read the <a href="http://c-faq.com/" rel="nofollow noreferrer">C FAQ</a>.</p></li> </ol>
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload