Skupiny Google už nepodporujú nové príspevky ani odbery Usenet. Historický obsah zostáva viditeľný.

int *p vs int* p

77 zobrazení
Preskočiť na prvú neprečítanú správu

David Xingliang Lou (CS 137 Tutor)

neprečítané,
5. 11. 2010, 13:42:175. 11. 2010
komu:
Do you have a strong preference towards either int *p or int* p?

http://www.student.cs.uwaterloo.ca/~cs137/current/res/intstarp.shtml

Rob Schluntz (CS241 Tutor)

neprečítané,
29. 11. 2010, 14:30:0229. 11. 2010
komu:
David Xingliang Lou (CS 137 Tutor) wrote:
> Do you have a strong preference towards either int *p or int* p?
>
> http://www.student.cs.uwaterloo.ca/~cs137/current/res/intstarp.shtml

I have a preference towards int* p. This is because (int*) is a type: an
integer pointer, with a variable named p. On the other hand, "int *p"
reads "type: integer", with a pointer to a variable: p. Here int* is a
type, the type isn't just int. Same as if you had (char* c), which would
be a pointer to a character, not (char *c): a pure character type.

</devil's advocate>

David Xingliang Lou (CS 137 Tutor)

neprečítané,
29. 11. 2010, 15:16:3629. 11. 2010
komu:

Let me try to understand your argument.

So you said, because the type of p is an integer pointer, we should
naturally group the type name (int*) as a single entity. A declaration
like (int *p) groups the variable name and part of the type name
together, which looks weird. Am I understanding you correctly?

Then, Rob, let me ask you this. What is the type of the foo:

int *(*(*foo[4])(int x, int y))[5];

The type of foo is (int *(*(*[4])(int,int))[5]) (an array of pointers to
functions that takes 2 integer parameters, and returns a pointer to an
array of pointers to integers), but notice that you don't just say

int *(*(*[4])(int,int))[5] foo; //syntax error

You DON'T put the variable name at the end (like you do when you say
int* p), you put it in the MIDDLE, around the stars and brackets. This
is how variables are declared in C. This is how the compiler read them.
(int *p) is consistent with this idea.

What do you have to say to that, Rob? :)

dkho...@gmail.com

neprečítané,
26. 7. 2013, 19:44:0526. 7. 2013
komu:
On Friday, November 5, 2010 10:42:17 AM UTC-7, David Xingliang Lou (CS 137 Tutor) wrote:
> Do you have a strong preference towards either int *p or int* p?
>
> http://www.student.cs.uwaterloo.ca/~cs137/current/res/intstarp.shtml



fgmdhgkdfgdsks
ghlfdlk
gfdfk
ghhg
hgfhfkg djbfaef vds
0 nových správ