[gameprogrammer] A Note on C Programming Style
- From: Chris Nystrom <cnystrom@xxxxxxxxx>
- To: gameprogrammer@xxxxxxxxxxxxx
- Date: Thu, 5 May 2005 15:23:14 -0500
Hi,
Here is a small rant on C programming style from my blog, that some
beginners might find useful:
--
It is widely believe that pointers are a difficult area in C
programming. Joel on Software mentions it in his hiring essay, for
example. However, I do not think that they are that hard to
understand. They are, after all, just variables that contain memory
addresses.
I do think that C convention does confuse the issue though. For
example, most people when they create pointer variables do so like
this:
char *p;
which means character pointer p. However, everyplace else variables
are defined it is:
type variablename;
That is type space variablename. In the above example, it looks like
the variable name is *p, but it is not, it is just p.
This gets especially confusing when using the unary operator (*) to
de-refrence the variable, which is, of course, quite common. The
important point is that *p in a variable definition is quite different
than *p in logic code.
For this reason, I believe it would be better to write pointer definitions:
char* p;
Note that the space is now between the * and the pointer name, and
also that the change has no effect on the code itself.
I know this is a small point, but this seems to me to be a clearer
definition of a character pointer named p, and also makes it is
clearer what *p means, that it is different from the pointer named p.
Chris
--=20
E-Mail: Chris Nystrom <cnystrom@xxxxxxxxx>
Business: http://www.shaklee.net/austin
Blog: http://conversazione.blogspot.com/
AIM: nystromchris
---------------------
To unsubscribe go to http://gameprogrammer.com/mailinglist.html
- Follow-Ups:
- [gameprogrammer] Re: A Note on C Programming Style
- From: Wes Wannemacher
Other related posts:
- » [gameprogrammer] A Note on C Programming Style
- » [gameprogrammer] Re: A Note on C Programming Style
- » [gameprogrammer] Re: A Note on C Programming Style
- » [gameprogrammer] Re: A Note on C Programming Style
- » [gameprogrammer] Re: A Note on C Programming Style
- » [gameprogrammer] Re: A Note on C Programming Style
- » [gameprogrammer] Re: A Note on C Programming Style
- » [gameprogrammer] Re: A Note on C Programming Style
- » [gameprogrammer] Re: A Note on C Programming Style
- » [gameprogrammer] Re: A Note on C Programming Style
- » [gameprogrammer] Re: A Note on C Programming Style
- » [gameprogrammer] Re: A Note on C Programming Style
- » [gameprogrammer] Re: A Note on C Programming Style
- » [gameprogrammer] Re: A Note on C Programming Style
- » [gameprogrammer] Re: A Note on C Programming Style
- » [gameprogrammer] Re: A Note on C Programming Style
- » [gameprogrammer] Re: A Note on C Programming Style
- » [gameprogrammer] Re: A Note on C Programming Style
- » [gameprogrammer] Re: A Note on C Programming Style
- » [gameprogrammer] Re: A Note on C Programming Style
- » [gameprogrammer] Re: A Note on C Programming Style
- » [gameprogrammer] Re: A Note on C Programming Style
- [gameprogrammer] Re: A Note on C Programming Style
- From: Wes Wannemacher