Spaces, stars, and pointers
-
so what do all of you believe? That you are wrong. :)
char* data, data2;
The format implies that both data and data2 are pointers which is totally wrong.
char *data, data2;
This format implies that data is a pointer while data2 isn't. Of course, this assumes that you define multiple variables per line. Which isn't really a good idea given the ambiguity of the two previous statements. Tim Smith Descartes Systems Sciences, Inc.
Very good point Tim. Maybe thats why I liked the other one subconciously :-) Nish Sonork ID 100.9786 voidmain www.busterboy.org If you don't find me on CP, I'll be at Bob's HungOut
-
Tim Smith wrote: char* data, data2; If you write that expecting data2 to be a char*,then you don't understand the syntax. Putting the * next to the type is still clearer. ;) ;P --Mike-- My really out-of-date homepage "Why does anyone have a web page? Too much free time... not enough friends... justifying owning a computer." -- Noel Crane on Felicity Sonork - 100.10414 AcidHelm Big fan of Alyson Hannigan.
You know what could be really dangerous? say someone does this. LPTSTR y1,y2; y1 is now a char * and y2 is a char. But without the '*' things can be vague,,, Nish Sonork ID 100.9786 voidmain www.busterboy.org If you don't find me on CP, I'll be at Bob's HungOut
-
Personally, I believe this: char* data; is superior to this: char *data; Because char*, or variable*, more easily identifies the fact you are declaring a pointer. Likewise, char *data="hello"; is inferior to char* data = "hello"; Because the spaces more clearly identify that information you're assigning to the variable. Obviously, this is personal taste and cannot be objectively true, so what do all of you believe?
-
You know what could be really dangerous? say someone does this. LPTSTR y1,y2; y1 is now a char * and y2 is a char. But without the '*' things can be vague,,, Nish Sonork ID 100.9786 voidmain www.busterboy.org If you don't find me on CP, I'll be at Bob's HungOut
Nish [BusterBoy] wrote: LPTSTR y1,y2; y1 is now a char * and y2 is a char. bzzzt, wrong. Sorry, you don't get to go on to Final Jeopardy. y1 and y2 are both LPTSTR :) --Mike-- My really out-of-date homepage "Why does anyone have a web page? Too much free time... not enough friends... justifying owning a computer." -- Noel Crane on Felicity Sonork - 100.10414 AcidHelm Big fan of Alyson Hannigan.
-
Nish [BusterBoy] wrote: LPTSTR y1,y2; y1 is now a char * and y2 is a char. bzzzt, wrong. Sorry, you don't get to go on to Final Jeopardy. y1 and y2 are both LPTSTR :) --Mike-- My really out-of-date homepage "Why does anyone have a web page? Too much free time... not enough friends... justifying owning a computer." -- Noel Crane on Felicity Sonork - 100.10414 AcidHelm Big fan of Alyson Hannigan.
how come Mike? I am puzzled I checked through the chain of typedefs and finally decided that an LPTSTR is a char* and nothin else but a char* oh!!!!! you mean the "typedef" does the trick eh???? gosh!!!! My C basics is bad :-( Nish Sonork ID 100.9786 voidmain www.busterboy.org If you don't find me on CP, I'll be at Bob's HungOut
-
how come Mike? I am puzzled I checked through the chain of typedefs and finally decided that an LPTSTR is a char* and nothin else but a char* oh!!!!! you mean the "typedef" does the trick eh???? gosh!!!! My C basics is bad :-( Nish Sonork ID 100.9786 voidmain www.busterboy.org If you don't find me on CP, I'll be at Bob's HungOut
Nish [BusterBoy] wrote: you mean the "typedef" does the trick eh???? Yep :) "LPTSTR" becomes a type name, just like "int" or any other built-in type. --Mike-- My really out-of-date homepage "Why does anyone have a web page? Too much free time... not enough friends... justifying owning a computer." -- Noel Crane on Felicity Sonork - 100.10414 AcidHelm Big fan of Alyson Hannigan.
-
Nish [BusterBoy] wrote: you mean the "typedef" does the trick eh???? Yep :) "LPTSTR" becomes a type name, just like "int" or any other built-in type. --Mike-- My really out-of-date homepage "Why does anyone have a web page? Too much free time... not enough friends... justifying owning a computer." -- Noel Crane on Felicity Sonork - 100.10414 AcidHelm Big fan of Alyson Hannigan.
Thanks Mike. I think I can use this as an interview question next time we recruit :-) Nish Sonork ID 100.9786 voidmain www.busterboy.org If you don't find me on CP, I'll be at Bob's HungOut
-
so what do all of you believe? That you are wrong. :)
char* data, data2;
The format implies that both data and data2 are pointers which is totally wrong.
char *data, data2;
This format implies that data is a pointer while data2 isn't. Of course, this assumes that you define multiple variables per line. Which isn't really a good idea given the ambiguity of the two previous statements. Tim Smith Descartes Systems Sciences, Inc.
-
You know what could be really dangerous? say someone does this. LPTSTR y1,y2; y1 is now a char * and y2 is a char. But without the '*' things can be vague,,, Nish Sonork ID 100.9786 voidmain www.busterboy.org If you don't find me on CP, I'll be at Bob's HungOut
:eek: Don‘t do that! Your post startled me. I have on occasion declared LPTSTR y1, y2; After reading your post I started remembering all the code I used like this so I could fix it before it crashed. X| I now truly understand the purpose of typedef. :-O
-
Personally, I believe this: char* data; is superior to this: char *data; Because char*, or variable*, more easily identifies the fact you are declaring a pointer. Likewise, char *data="hello"; is inferior to char* data = "hello"; Because the spaces more clearly identify that information you're assigning to the variable. Obviously, this is personal taste and cannot be objectively true, so what do all of you believe?
I agree with you. If there was area for confusion like Tim mentioned above, I would simply declare the variable on a new line. ________________ David Wulff http://www.davidwulff.co.uk "I loathe people who keep dogs. They are cowards who haven't got the guts to bite people themselves" - August Strindberg
-
so what do all of you believe? That you are wrong. :)
char* data, data2;
The format implies that both data and data2 are pointers which is totally wrong.
char *data, data2;
This format implies that data is a pointer while data2 isn't. Of course, this assumes that you define multiple variables per line. Which isn't really a good idea given the ambiguity of the two previous statements. Tim Smith Descartes Systems Sciences, Inc.
I totally agree with you :-) - Anders Money talks, but all mine ever says is "Goodbye!"
-
Personally, I believe this: char* data; is superior to this: char *data; Because char*, or variable*, more easily identifies the fact you are declaring a pointer. Likewise, char *data="hello"; is inferior to char* data = "hello"; Because the spaces more clearly identify that information you're assigning to the variable. Obviously, this is personal taste and cannot be objectively true, so what do all of you believe?
I tend to go for char * data; which clearly shows that the * is a seperate entity which modifys the meaning of the former, and aids in defining the latter. Even if I could, I would not say staticconstchar data, so why would I not also space out the * ? The fact that multiple variables on the one line each need the *, if they are pointers, is another reason I would not space them as you have. However, while I can smell a poll coming on ( and if you're reading Chris, I'd prefer a poll on if people use STL and why/why not), it is, as you say, ultimately a matter of choice. Christian After all, there's nothing wrong with an elite as long as I'm allowed to be part of it!! - Mike Burston Oct 23, 2001
Sonork ID 100.10002:MeanManOz
I live in Bob's HungOut now