Beta

×

Welcome to the Slashdot Beta site -- learn more here. Use the link in the footer or click here to return to the Classic version of Slashdot.

Thank you!

Before you choose to head back to the Classic look of the site, we'd appreciate it if you share your thoughts on the Beta; your feedback is what drives our ongoing development.

Beta is different and we value you taking the time to try it out. Please take a look at the changes we've made in Beta and  learn more about it. Thanks for reading, and for making the site better!

Advanced C Programming by Example

Hemos posted more than 15 years ago | from the learn-by-seeing dept.

News 47

LizardKing has sent us a review of John Perry's Advanced C Programming by Example. Covering topics such as pointer trickery, string manipulation and dynamic data structures, this book is designed for those of you who are looking to fine-tune your C skills. Click below for more information.

The Scenario

Having been given a book voucher for Christmas, I duly trotted off to Blackwell's bookshop in Oxford to see what I could spend it on. I did the obligatory check for new O'Reilly titles, before turning to the C books. A hardback copy of Kamp II to replace my dog-eared paperback would've been nice, but first I decided to flick through Advanced C Programming by Example. The contents page promised examples of pointer trickery, string manipulation and dynamic data structures. I consequently bought it.

What's Bad?

There is very little to fault this book on. It is written in a clear and enjoyable manner, which is about the best you can hope for from a programming guide. My only real criticism is the lack of a bibliography. For instance, cryptography is mentioned in the chapter on bit manipulation, but no references to further reading are given.

What's Good?

The introduction explains the rationale behind producing another C book by pointing to the dearth of intermediate level texts. The author also criticises the current emphasis on OO languages with their larger vocabulary and more abstract concepts.

The first chapter highlights the importance of coding style to aid maintainability, and the valid use of features like the ternary and comma operators. This is followed by an excellent review of pointer theory. I always judge a C book by how clearly it describes the purpose of pointers - and this one does it superbly.

Subsequent chapters contain in depth analysis of key data structures like singly and doubly linked lists, binary trees, etc. While most C books include examples of these, they are particularily well described and illustrated. Other important techniques like hashing (both to memory and disk) are introduced, with common pitfalls highlighted.

The bit manipulation chapter is comparable with those in other C texts, but is unusually clear and consistent. The same can be said of the advanced I/O chapter.

The chapter on string manipulation uses dynamic memory allocation, arrays of pointers and the more obscure ANSI C string functions for 'real world' examples. This is another area where many C books fall down, ignoring the fact that the strings many programmers deal with cannot be expected to fit into fixed length arrays.

The final "Pot-Pourri" chapters include a discussion of complex function declarations that both expect and return function pointers. A number of other rarely described but expressive features are also covered.

So What's In It For Me?

If you consider yourself a C expert, then this book may be superfluous, as it covers ideas and principles you should know intimately. But if like me you're spending more time with scripting languages like Perl, you may need a handy reference for those forays back into C.

Buy this book here.

Table of Contents

  1. Optimal C Coding Style
  2. Review of Standard Pointer and Array Operations
  3. The Linear Dynamic Data Structures: Stacks, Queues and Linked Lists
  4. Advanced String Handling
  5. Advanced Input and Output
  6. Bit Manipulation
  7. Recursion and Binary Trees
  8. Multidimensional Arrays and Arrays of (Non-Char) Pointers
  9. Potpourri: Part One
  10. Potpourri: Part Two
  11. Answers to Selected Exercises

cancel ×

47 comments

Sorry! There are no comments related to the filter you selected.

C is dumb (0)

Anonymous Coward | more than 15 years ago | (#2036025)

They should have a book on C++ instead!

Promising (0)

Anonymous Coward | more than 15 years ago | (#2036026)

This sounds promising... I'll probably pick it up based on this synopsis.

Function Pointers? (0)

Anonymous Coward | more than 15 years ago | (#2036027)

Nice review; thanks.

Does the book cover function pointers in any
detail?

my books and pointers == bad mix (0)

Anonymous Coward | more than 15 years ago | (#2036028)

all the c books i have (or rather the ones that are required texts for school) fall short in terms of pointers. one chapter out of 15 is lacklustre. i might pick this book up based on the review.

later
tyler

C: 1960's technology, today (0)

Anonymous Coward | more than 15 years ago | (#2036029)

Common folks, the C language is 1960's technology. C is great for writing error-prone programs. (If you don't believe me, check out the Fuzz paper where about 25% of common unix utility programs crash when you give them random input).

One of the posters here wanted to learn more about function pointers. For almost any task, a decent programming language doesn't need pointers (user manipulable machine addresses). All you need is references. With references you get safety, and you don't need lose any power...

c stuff (0)

Anonymous Coward | more than 15 years ago | (#2036030)

anyone reccomend a good encryption book for c/c++ ?

Wow, I know this guy. (0)

Anonymous Coward | more than 15 years ago | (#2036031)

Years ago I took a C course taught by Greg Perry
at Tulsa Junior College before he started writing books full time. He was a really good teacher, so I expect his book to be very good as well.

all you idiots putting down C (0)

Anonymous Coward | more than 15 years ago | (#2036032)

making fun of C is making fun of the foundation
on which all you know is built.

the title! (0)

Anonymous Coward | more than 15 years ago | (#2036033)

Hmmm... the title isn't *quite* similar enough to the titles of other famous books for me... how about this one:

"The Art of Advanced C Programming by Example for Dummies in a Nutshell"

how about that, is that vaguely familiar enough for you?

Where is the FUZZ PAPER you speak of? (0)

Anonymous Coward | more than 15 years ago | (#2036034)

Citations? Thanks!

C: 1960's technology, today (0)

Anonymous Coward | more than 15 years ago | (#2036035)

> Function pointers have come in pretty handy to me as
> an elegant and fast way to call different functions
> depending on the program's state.

Function pointers are handy... but guess what?... A language doesn't need pointers to do the equivalent thing. All you need is references to functions... The programmer doesn't need to manipulate machine addresses directly... the programming language should take care of that for you. References give you all the power of pointers, but with safety.

Pointer errors are one of the most common errors in C programs.

C is dumb (0)

Anonymous Coward | more than 15 years ago | (#2036036)

The thing i like about java is that all classes inherit from Object. I prefer to use/code containers this way than with c++ template. But i know a lot of people prefer generic programming, i would like to know why? what are the advantage?

i learn OO with C++, but now i prefer java, the syntax is much nicer. never used objective-c but the syntax looks very special..


cob2k25@iebgener.org

Well I am interested.. (0)

Anonymous Coward | more than 15 years ago | (#2036037)

I am/was interested in purchasing the book, however I wanded to first browse through it before purchasing it. Money is tight when your a student :]. Unfortunately, 5 different book stores all indicated that they were out of stock. :[.

Re: C is dumb (0)

Anonymous Coward | more than 15 years ago | (#2036038)

C is to C++ as Lung is to Lung cancer.

Whats better? (0)

Anonymous Coward | more than 15 years ago | (#2036039)

If C sucks so bad then is there anything better that compiles natively. Java may be a great language but I have no need for cross platform compatibility and it just makes it slow.

Why C is not my favorite programming language (0)

Anonymous Coward | more than 15 years ago | (#2036040)

>
> for sheer expressive power, Perl is unbeatable
>

Only in a very limited domain. In most domains, Perl is not very good at abstracting complexity. Can you imagine wrapping some really nasty libraries in Perl to make the library easier to use, say Microsoft's OLE for instance?

The Dylan programming language is quite capable of doing this:

http://www.harlequin.com/products/ads/dylan/com/ comsimplifiedtext.html

Dylan code is also very efficient.

Troll Bridge (was: C is dumb) (0)

Anonymous Coward | more than 15 years ago | (#2036041)

Stop.

Pay Troll.

Why C is not my favorite programming language (0)

Anonymous Coward | more than 15 years ago | (#2036042)

"but I doubt if you are very familiar with some of the other languages" Why would you assume that? How could you possibly have any idea what programming languages that person uses for what kinds of programs? (Heh, perhaps the person is developing code for, say, Python, in which case C's still pretty important for now.)

Whats better? (0)

Anonymous Coward | more than 15 years ago | (#2036043)

You'll notice from the graphs on your reference, that although C/C++ scores very low on the comlexity scale (ie, it is more complex than most languages) even MSVC++, a microsoft implementation, scores as one of the highest contenders as far as speed goes... which means, if the major issue for your project is speed, use C/C++.

Alogorithm books ... not for me (0)

Anonymous Coward | more than 15 years ago | (#2036044)

I agree, but I have met more examples of programmers who write inefficient algorythms, and who don't even know what a binary tree is than I have over educated theorists.

Wow, I know this guy. (0)

Anonymous Coward | more than 15 years ago | (#2036045)

My mistake. I guess I assumed it was his because of the "___ by Example" title. A lot of his books follow that form.

C: 1960's technology, today (0)

Anonymous Coward | more than 15 years ago | (#2036046)

id Software uses ANSI C for core technology. That
is the claim by Brian Hook (in an article on Quake II
in Game Developer magazine). I have never had an
id Software product crash on me. Maybe I was just
lucky, eh?

Are we talking Pascal here... (0)

Anonymous Coward | more than 15 years ago | (#2036047)

1. If that code snippet's supposed to be C, you do realize that you're making an assignment and not an equivalency test, no?
2. In my experience, "language zealots", for *any* programming language, often do not have much breadth or of programming experience. Nothing at all to do with C (check the various "vs." language "wars" on USENET).

C is dumb (0)

Anonymous Coward | more than 15 years ago | (#2036048)

I tried learning C++ but I think OO programming is hard, C is much easier..

C: power to the people (1)

Tom (822) | more than 15 years ago | (#2036049)

while I agree that C is error-prone, it's also the most powerful language I've ever encountered, and that's exactly why I stick with it.
C is very much like unix: more power than you can handle, and if you burn yourself, it's your fault. I've yet to find a C problem that way not caused by bad design and/or bad implementation.
and taking care is the prize you pay for power. so if you can't handle it, then stay away from it. but stop telling me what to do. thank you.

Are we talking Pascal here... (1)

Dave Fiddes (832) | more than 15 years ago | (#2036050)

Or ada or any other strongly typed language...

I spend a lot of my spare time programming embedded systems in C...and some of it is a real grind compared to the day job programming in Delphi/Object Pascal. What language would allow this!

if ( Finished = TRUE )
{
PerhapsIllNeverGetRun();
}

It is my experience that C zealots rarely know many other languages

PICK ON C? GO TO JAIL! :) (1)

jabbo (860) | more than 15 years ago | (#2036051)

Big deal, so you use a typedef to mask this in the libraries. What's your point?

Why C is not my favorite programming language (1)

kip3f (1210) | more than 15 years ago | (#2036052)

1) People write programs to solve problems.
2) Problems are complicated (in general), and require
complicated solutions.
3) "Efficicent" [1] languages like C/C++ make the programmer
deal with complexities that are unrelated to the actual problem.
4) Hence C is not my favorite programming language.
[1] When people say "C is efficient", they are talking about
the speed of the resulting executable. OTOH 99.44% of the time,
it is much better to optimize *Programmer Efficiency*.

Perl (1)

kip3f (1210) | more than 15 years ago | (#2036053)

Sure. At the moment, Perl is my favorite programming language. There are a few misfeatures, like allowing both $foo and @foo, my $bar has nothing to do with *bar, debugging can be challenging due to the permissive nature of the language, no symbol for handles (they are a first class type, and deserve to be treated like one!).

What I would really like to see is increased flexibility in the typeglob. This should be a (C style) union [typesafe ;-)], where you can add new types (eg: a tree type). Also, more TIE* stuff.

Price Check (1)

Ralph Bearpark (2819) | more than 15 years ago | (#2036054)

Amazon $45.95
AlphabetStreet (UK) $34.25
BarnesAndNoble $44.95
Dymocks (AUS) US$31.29
Spree $36.76

Regards, Ralph.

C is dumb? (1)

W84thend (3549) | more than 15 years ago | (#2036055)

C is the basis of C++ (A real hack job of a programming language held together with baling wire and duct tape to give C programmers an OO language (it's not a real OO environment, but an incredible simulation!) without having to learn a whole new language.).
If you think C++ is so great for things like kernal programming then look closer at why Win95 crashes so much. Did you ever notice that modules don't always load in the same sequence?
Saying that C is dumb just proves what an asenine egotist you are. You don't understand the basis of the tools you are using.
There are very good reason's why 1. kernal programming, 2. embedded systems, 3. low level devices are done in C and not C++.
Java will one day surplant C++ as the standard OO design platform and not a day too soon. When that happens, C will still be used widely for many tasks which are unsuited to Java.
If you don't understand these basic issues, then I recommend you go back to Visual Basic programming and leave the system programming to people with more brains than you have.

PICK ON C? GO TO JAIL! :) (1)

Drizzt (3770) | more than 15 years ago | (#2036056)

Listen up C++ programs!

Do this in C++...

Cross platform/compiler. No real standard, no real cross platorm=no real widespread usage for cross platform work.

'nuff said.

:)

-Alan

Learning C = Learning C++ (1)

Mark Storer (4097) | more than 15 years ago | (#2036057)

C++ is a SUPERSET of C. Everything a wannabe hippster C++ programmer might learn from this book WILL APPLY DIRECTLY TO C++.

I use C++ and/or Java every day. You can bet I'll read this book sooner or later to make myself a better programmer in languages based on C (including Objective-C, for all you NeXT/Mac types out there).

Sokwuitcherbichin!

Calm down ... (1)

LizardKing (5245) | more than 15 years ago | (#2036058)

I agree that a more accurate title for Perry's
book would be `Intermediate C Programming', but
your distinctly rabid sentiments are wide of the
mark.

Deep C Secrets is a book that I mean to check out
at some point, but I was a little less than
enamoured with van der Linden's `Just Java' book.
It offers a lot of very good insights into Java,
but is lacking in example code.

As an aside, the classic view that C can *only* be
learnt from KnR II is a little suspect. It is
a great introductory text, and an even better
reference for C syntax, but it is a little too
bare bones for a standalone C tutorial.

C is dumb (1)

Vitus Wagner (5911) | more than 15 years ago | (#2036059)

If you've know a bit of C (or C++, it doesn't matter), you know that
C++ means "C grows larger, but result is as before". If Stroustroup had really intended
to build general replacement for C, not a language
which works better than C in _particular_ areas,
he'd call it ++C

I rather would judge by products written on it. (1)

Vitus Wagner (5911) | more than 15 years ago | (#2036060)

See:
apache - is written on C
Emacs - written on Lisp (so its way for OO programs)
Linux kernel - written on C
Gimp - written on C.
Perl - written on C
Tcl - written on C

So, where are good programs written on C++?
Nothing to name except KDE. But there is a lot
of problems with it. Is there web-servers war?
No - anyone prefer to contribute to apache.
But there is Desktop war, becouse too much people
don't like either Qt or C++ at all and starting
altertaitve desktop projects.

Consider number of programmers who would be
able to peer review and contribute to your code.
If you write in C every C _and_ C++ programmer
counts. If you write in C++, there are a lot
of people (and, more imprtant, compiliers)
who wouldn't understand what are you trying to
say.

Also, expert C programming (1)

andrew cooke (6522) | more than 15 years ago | (#2036061)

People might like to check out Van Der Linden's "Expert C Programming (Deep C Secrets)" - it's a very odd book, full of many random snippets, but it does contain some nuggets of useful wisdom.

Thanks for the review - I'll have a look for this book next time are out shopping...

Cheers,

Andrew

Can't judge a language by the people who use it (1)

Anil (7001) | more than 15 years ago | (#2036062)

I mean, I know some good programmers that are forced to use VisualBasic; doesn't make visual basic any better than the horrid excuse for a scripting language that it is.

I know some poor coders who try to code in C; doesn't make C a poor language.

C is dumb (1)

GypC (7592) | more than 15 years ago | (#2036063)

C++ is dumb... needlessly complex. ObjectiveC is much nicer.

the title! Let's do this! (1)

Bertelsmanniac (7634) | more than 15 years ago | (#2036064)

"Rescued By: Core Teach Yourself Zen and the Art of Advanced C Programming for C and C++ Programmers by Example for Dummies in a Nutshell Unleashed in 24 Hours for the Complete Idiot in 7 Days

C is dumb? (1)

dmeiz (9373) | more than 15 years ago | (#2036065)

i'd take a closer look at the nitwits in redmond before laying the blame on c++. true, c++ extends c to facilitate object oriented programming. a simulation? alright, i'll give you that; but it's quick and backward compatible and that ain't bad.

Price Check (1)

NYC (10100) | more than 15 years ago | (#2036066)

I always use http://www.acses.com to search online bookstores. It is a book search engine which tells you the price of a book with shipping included.

If you are looking for computer books look at http://www.bookpool.com. They are not indexed by acses.com, but they usually the cheapest and often out-of-stock.

Other new bookstores that seem promising:
http://www.shopping.com
http://www.buybooks.com (buycomp.com rocks!)

Never use amazon.com and barnesandnoble.com. They often lie about their selection (sure we have that in stock! oops, please wait 5 weeks)

Why buy this book? (1)

FigWig (10981) | more than 15 years ago | (#2036067)

The ultimate guide to C has got to be K&R. No one should be allowed to program C without it. Read it. Live it. Love it.

And if you need the linked-list-hash-table-b-tree stuff get a good algorithms book. I have heard Sedgewick (?) has written some good ones for C and C++.

C is dumb (1)

dxkelly (11295) | more than 15 years ago | (#2036068)

How can your learn C++ without learning C, when C is a subset of C++?

Your SOOO hip (1)

dimer (13155) | more than 15 years ago | (#2036069)

Man, I wish I was on top of the tech-wave like you are, ya know? Wait, lemme try...

"They should have a book on Shockwave instead!"

"They should have a book on JavaBeans instead!"

...whoa! If I'm ignorant and spout gay-ass buzzwords, then I'm cool! This is SOOO cool. I can't wait to tell my mom.

(Not saying C++ is bad or anything, but I am saying that straight-up C coding is a man's language.. Heheh)


C is dumb (1)

andyz (15208) | more than 15 years ago | (#2036070)

IMHO it's not true.
Programming language is the tool or instrument only. It can't be dumb.
But programmer (usually not a real programmer) can. And don't forget that the C++ is only preprocessor for pure C... I think that mindless plastic box (even 450 MHz with) can't be smarter than man's brain...

Why C is not my favorite programming language (1)

Badfish (94662) | more than 15 years ago | (#2036071)

What Inefficincies in perticular are you refferring to????

Quite frankly I LOVE C!
Check for New Comments
Slashdot Login

Need an Account?

Forgot your password?
or Connect with...

Don't worry, we never post anything without your permission.

Submission Text Formatting Tips

We support a small subset of HTML, namely these tags:

  • b
  • i
  • p
  • br
  • a
  • ol
  • ul
  • li
  • dl
  • dt
  • dd
  • em
  • strong
  • tt
  • blockquote
  • div
  • quote
  • ecode

"ecode" can be used for code snippets, for example:

<ecode>    while(1) { do_something(); } </ecode>