I didn't know this after 14 years of C/C++
Node *next,*prev;
It should work
If you code it, they will come...
Commander M
http://commanderm.8m.com
cmndrm@commanderm.8m.com
class Node
{
Node* prev, next;
}
is eq to
class Node
{
Node* prev;
Node next;
}
Note that there is no * in front of next...
oops somebody replied already....
-kertropp
C:\Projects\rg_clue\ph_opt.c(185) : error C3142: 'PushAll' :bad idea
C:\Projects\rg_clue\ph_opt.c(207) : error C324: 'TryCnt': missing point
Dang!
Somehow I had convinced myself that my first C++ book (C++ for C Programmers by Ira Pohl) that I got in 1990 said there was a change in pointer declaration syntax (it doesn''t). I though the change resulted in the fact that the line ''int* p, q;'' created two integer pointers and that ''int *p, q'' would be one integer pointer and one integer.
I guess I got confused because I had always used the form ''int *p, *q'' and in Pohl''s book he uses two lines, ''int *p;'' and ''int *q''. For some reason this screwed with my mojo and I thought that ''int* p, q'' would do the job. )
Funny thing is that at work (pure C stuff) I still use ''int *p'' to stay in style with some older code (older code of mine) and at home I must have never needed to declare two pointers at home where I had adopted ''int* p;''. So when I needed two pointers I just did ''int* p, q'' which is dead wrong.
About two minutes after reading Kertropp''s post (thanks for the pointing out the obvious Kertropp! ) I found in my newer C++ book (2nd Edition C++ Primer Plus by Stephen Prata)on page 121 a very specific warning to not do what I did. Dang nabbit and sufferin succotash! And to think I was one those C programmers who, due to earlier assembly programming experience, pretty quickly (and fully) understood pointers.
The real irony I guess is that I bought Pohl''s book because I learned C from a book he wrote with Al Kelley called ''A Book on C'' that I loved so much, as was so complete, that I never needed another. I''ve never even needed the ''must have book'' by Kerningham and Ritchie. And then ole Ira screws with mind!
Michael L. Roberts
aka milo
mlbobs@telocity.com
(but i didn''t post it up the board.. )
Doesn''t it seem more logical that
Blah * prev, next;
*should* be the same as
blah * prev,
* next;
or whatever... I guess that''s why there is usually a data type, then an LP data type in most code.
ie
BYTE a, b;
just so you don''t have to put that damn asterisk! =)
LPBYTE a, b;
Rather than
String * pString;
I have
String *pString;
Just makes it a bit more obvious to me. Some books seem to do the opposite, putting the adornment on the type, which is downright confusing.
(my byline from the Gamedev Collection series, which I co-edited) John Hattan has been working steadily in the casual game-space since the TRS-80 days and professionally since 1990. After seeing his small-format games turned down for what turned out to be Tandy's last PC release, he took them independent, eventually releasing them as several discount game-packs through a couple of publishers. The packs are actually still available on store-shelves, although you'll need a keen eye to find them nowadays. He continues to work in the casual game-space as an independent developer, largely working on games in Flash for his website, The Code Zone (www.thecodezone.com). His current scheme is to distribute his games virally on various web-portals and widget platforms. In addition, John writes weekly product reviews and blogs (over ten years old) for www.gamedev.net from his home office where he lives with his wife and daughter in their home in the woods near Lake Grapevine in Texas.
quote: Original post by johnhattan
One thing I always make a point of doing is to attach the notation to the variable, not the type.
Rather than
String * pString;
I have
String *pString;
Just makes it a bit more obvious to me. Some books seem to do the opposite, putting the adornment on the type, which is downright confusing.
Well, your way makes it more difficult to make a mistake in declaring pointers, which is good. But the other way (String* pString ) is equally valid as it follows the syntax of any other (ie. non-pointer) definition, which is type on the left (in this case, pointer to string), name on the right (pString). Personally I prefer this way, as my variable is of type String*. It just means I have to declare everything on separate lines to be clear.
#pragma DWIM // Do What I Mean!
~ Mad Keith ~
**I use Software Mode**