Breaking News
Engineerís Bookshelf

Understanding and Using C Pointers

NO RATINGS
View Comments: Oldest First | Newest First | Threaded View
Page 1 / 2   >   >>
betajet
User Rank
CEO
C Function pointers
betajet   2/25/2014 4:44:19 PM
Well, getting a C function pointer declaration right is a book in itself :-)

glagnx
User Rank
Rookie
Re: C Function pointers
glagnx   2/27/2014 10:26:17 AM
NO RATINGS
C Pointers have been ignored by some for as long as the language has existed. I read this sentence over 15 years ago and I guess people still want to ignore a great tool. The reality is that pointers are essential for any programmer. At my embedded systems consulting company we still see customers that pass huge variables, often blowing up the stack and we have to explain pointers and how they should avoid passing such large elements.


AS the post by CEO points, function pointers can be a bit tricky, but oftentimes using them to create a dynamic handler can make branching to different handlers very extensible, and I think that is something very desirable.

Avoiding pointers is like a mechanic not using power tools. Sure, you can hurt yourself, but if you learn to leverage them you can do the job quicker and cleaner.

LarryM99
User Rank
CEO
Re: C Function pointers
LarryM99   2/27/2014 4:50:44 PM
NO RATINGS
There are some subtleties about pointers, but it still seems like a pretty narrow topic. The entire C language was described in what is actually a reasonably compact book, after all. I would at least hope that it also covers smart pointers as defined in the latest c++ standards. Restricting the book to common C usage means that it is of use to a much smaller audience.

Max The Magnificent
User Rank
Blogger
I need to get this book
Max The Magnificent   3/1/2014 10:43:36 AM
NO RATINGS
Hi Jack -- I'm not a programmer -- I just dabble -- but recently I've found myself having to use pointers and sometimes I find it hard to wrap my brain around -- I think I need to get a copy of this book.

vlsi_guy
User Rank
Manager
Re: I need to get this book
vlsi_guy   3/1/2014 10:56:32 AM
NO RATINGS
I concur, while I've probably written more software in my career then others who consider them selves hardware engineers (hudreds of thousands of lines of code in either C/C++/mainsail/perl/tcl/python) and while pointers are conceptally very easy to understand. When you bounce around between interpretted and compiled languages all the time I tend to forget about the "nuances" between how pointers our implemented in one language versus how to referance a variable location in another.

 

So, I for one think a dedicated book on the subject (albeit w.r.t. just C/C++) should have come years ago :-).

 

Going to Amazon now to pick me up a copy...

 

Max The Magnificent
User Rank
Blogger
Re: I need to get this book
Max The Magnificent   3/1/2014 11:01:58 AM
NO RATINGS
@vlsi_guy: Going to Amazon now to pick me up a copy...

That spurred me into action -- I was going to add it to my wish list -- and then I read the comment about referecing pointers to functions and I decided not to wait -- so I just ordered a copy :-)

ghova
User Rank
Manager
Dread
ghova   3/3/2014 9:37:35 AM
I have a pacemaker.  The thought that, in the 21st century, it might be coded in C fills me with dread.

RGARVIN640
User Rank
Manager
Re: Dread
RGARVIN640   3/13/2014 4:54:34 PM
NO RATINGS
For me, it is the exact opposite. The thought of any safety critical code NOT being in C or assmbler fills me with dread.

ghova
User Rank
Manager
Re: Dread
ghova   3/14/2014 3:51:11 PM
NO RATINGS
In case you find my 'dread' as baffling as I yours, let me outline my reasons.  C was created (~1972) and adopted by people who were currently writing in assembly language.  They saw the Index Register as an essential element of programming and, understandably, enshrined it in their new language as the Pointer.  This was the Tricky Age of programming where cool tricks were greatly admired, and the pointer is one of the coolest, because you can do amazing tricks with it and produce startling effects, though not necessarily the ones you intended.  40+ years later people are still doing this.

IMO the greatest advance in pointer technology was its removal.  This is accomplished neatly in Java.  Because of this, and the fact that all array references are checked, it is impossible to access any memory not explicitly named in your program.  Further, there are Java systems that can calculate absolute upper limits on the execution time of code, which allows one to know if scheduling deadlines can be met.  In addition, there are garbage collectors whose execution time is known and which can operate concurrently with user code.  These features have allowed the definition of a "Safety Critical Java."  One of the best known and most highly developed of these is Martin Schoeberl's JOP (Java Optimized Processor).  It has the novel feature that the "operating system" (which reduces to a scheduler) is itself written in Java.  No memory management unit is needed.  There is also a multiprocessor version.

I'm not knowledgeable about the existence of a Safety Critical C, but a quick search turns up many suggestions for making C safer (but not Safe).  I can only hope that some pointer blunder won't send my pacer into Lala land.

Max The Magnificent
User Rank
Blogger
Love the book
Max The Magnificent   3/21/2014 6:12:01 PM
NO RATINGS
Based on this column I ordered the book -- I'm only a couple of chapters in, but I think just the parts I've read were "worth the price of admission," and I'm looking forward to learning more.

Page 1 / 2   >   >>
More Blogs from Engineerís Bookshelf
Software tools and techniques for global software development. Dr. Dobb's features articles, source code, blogs,forums,video tutorials, and audio podcasts, as well as articles from Dr. Dobb's Journal, BYTE.com, C/C++ Users Journal, and Software Development magazine.
The lack of quality manuals and documentation for developer tools greatly diminishes our ability to work well in subtle but important ways.
Engineers make design decisions that affect the company bottom line, often without understanding how.
How many cubic feet of soil can you fertilize with your excrement? This is the kind of problem that has to be solved if you're stranded on Mars and have to grow food to survive.
Here are six great examples of science fiction authors who truly inspired new technology.
Most Recent Comments
Radio
NEXT UPCOMING BROADCAST
EE Times Senior Technical Editor Martin Rowe will interview EMC engineer Kenneth Wyatt.
Top Comments of the Week
Like Us on Facebook

Datasheets.com Parts Search

185 million searchable parts
(please enter a part number or hit search to begin)
EE Times on Twitter
EE Times Twitter Feed
Flash Poll