Dealing with pointer freaks

M. P. Gerlek mikeg at c3.c3.lanl.gov
Wed Jun 26 01:31:37 AEST 1991


In article <sherman.677844151 at foster> sherman at unx.sas.com (Chris Sherman) writes:
> IMHO, leave the dude alone.  Jump up and down when you find major problems
>    [...]
> but for things like *(x+i), don't worry about it. 

Yes, x[i] is just *(x+i), but consider what x[a][b+k][j+1] turns into.
I can't believe more than a handful of you could look at the
"pointer-ized" expression for x[a][b+k][j+1] and *immediately* tell
what it means.  We're considering readability of code, here.

As an example, consider coding some sort of numerical, linear algebra
sort of algorithm.  The mathematical expression can be fairly quickly
translated into C, substituting x-sub-i-sub-j ("x_ij") for x[i][j].
It's not obvious to the subsequent reader of the code that the
expression *(*(x+i)+j) is simply x[i][j], however.  You've lost
'readability'.

I'm amazed at the number of comments I've rec'd about using pointers
*instead of* simple array syntax.  Tell me it's just that I'm not
hearing a representative sample -- I refuse to believe the majority of
the net feels that there's no point in conforming to one set style
because, to quote some email, (a) there are too many styles, (b) if
YOU write the code YOU can do it however YOU want, and (c) anyone
using the code later should be able to just clean up the parts he or
she doesn't like.  (This last is particularly amazing :-)

Yes, I will grant that if the peiece of code you are doing is a
one-man project you can code it however you like -- but what happens
after you've left the shop, and someone else needs to use it?
Further, to get back to my original post, we're dealing with a case
where the programmer is programming solo _today_, but will be writing
code that he and others will have to port and modify _tomorrow_.

Finally, I've gotten responses saying that the Indian Hill style guide
is out-of-date and flat out wrong in places.  Will someone please post
a critique of the I.H. guide?  And please tell me what y'all use
instead?  If anything?

And as an aside to those of you who don't like "conventions" and
"styles" in C: do you put your #defined constants in all uppercase?
You do?  Care to explain why?

-[mpg]
 mikeg at lanl.gov
 "Headline: LANL High-speed Compooter Researchers Pay Raft Trip Subsidies"
--

-[mpg]
 mikeg at lanl.gov
 "Headline: LANL High-speed Compooter Researchers Pay Raft Trip Subsidies"



More information about the Comp.lang.c mailing list