Linked by Thom Holwerda on Tue 28th Aug 2012 19:20 UTC, submitted by MOS6510
General Development "Coming from a background in higher-level languages like Ruby, Scheme, or Haskell, learning C can be challenging. In addition to having to wrestle with C's lower-level features like manual memory management and pointers, you have to make do without a REPL. Once you get used to exploratory programming in a REPL, having to deal with the write-compile-run loop is a bit of a bummer. It occurred to me recently that I could use gdb as a pseudo-REPL for C. I've been experimenting with using gdb as a tool for learning C, rather than merely debugging C, and it's a lot of fun. My goal in this post is to show you that gdb is a great tool for learning C. I'll introduce you to a few of my favorite gdb commands, and then I'll demonstrate how you can use gdb to understand a notoriously tricky part of C: the difference between arrays and pointers."
Thread beginning with comment 532899
To read all comments associated with this story, please click here.
by l3v1 on Wed 29th Aug 2012 06:53 UTC
Member since:

We've seen that in some situations a acts like an array and in others it acts like a pointer to its first element. What's going on?

Coder from the clouds (*), meet C, C meet coder from the clouds.

is there a difference between the pointer that a decays to and &a ... decayed value of a is a pointer to a's first element ... distinction between a's decayed value and &a

Well, I'm all for a little experimentation and whatnot, but seriously, reading a bit about C/C++ (in this especially about pointers and related topics) before trying to poke around in the dark would really, really be the wise thing to do, for multiple reasons. You'd progress faster, understand easier, and wouldn't have to write such posts for no good reason, sorry.

(*) i.e. coding while flying so high, pointers can't be seen anymore

Reply Score: 3

by ephracis on Wed 29th Aug 2012 20:21 in reply to "C"
ephracis Member since:

Agreed. Pointers are really easy if you just read about them in any book or even on Wikipedia. But trying to understand pointers by poking around in a debugger might take a while.

Reply Parent Score: 2