Jump to content
  • Advertisement

Archived

This topic is now archived and is closed to further replies.

MadKiwi

Pointer asterisk placement

This topic is 5231 days old which is more than the 365 day threshold we allow for new replies. Please post a new topic.

If you intended to correct an error in the post then please contact us.

Recommended Posts

Hi, I did a search on this but couldn''t find any results. I just want to know the difference between the following 2 statements or are they the same? Substitute the char for any type. char* c; char *c;

Share this post


Link to post
Share on other sites
Advertisement
This has been flamed many times over, but ultimately
char *c  
is better because
 char* a,b,c,d  
is NOT the same as
char *a, *b, *c, *d  


[edited by - Kaezin on March 22, 2004 5:09:41 PM]

Share this post


Link to post
Share on other sites
I agree Kaezin,

The only time I use "char*" instead of "char *" is when its the data type of a function. Else, Any variables are always "char *" for me.
Example:

char* myFunction(char *a, char *b);


- [BDS]StackOverflow

Share this post


Link to post
Share on other sites
quote:
Original post by BlueDev
I agree Kaezin,

The only time I use "char*" instead of "char *" is when its the data type of a function. Else, Any variables are always "char *" for me.
Example:

char* myFunction(char *a, char *b);


- [BDS]StackOverflow


Thanks for your quick answers guys, this forum is awesome. Regarding using char* for a function: will char * not work for a function or is that just your preferred format?

Share this post


Link to post
Share on other sites
Hey MadKiwi,

Q. will char * not work for a function or is that just your preferred format?

A. Just a preferred format. It's easier when you have preferences so when you look at your code things formulate faster than trying to figure out what this is, where it is, how it is, and etc...

Glad you are enjoying the boards There are some skilled programmers here (including myself ) that wont mind helping you out when you need.

If you ever feel that your post is not recieveing any replies, no worries, either no one is interested in the topic or the question is out of some of our league. Either way, I'll try replying with some sort of answer even if it isn't the best.


- [BDS]StackOverflow

[edited by - BlueDev on March 22, 2004 6:12:23 PM]

Share this post


Link to post
Share on other sites
quote:
Original post by Kaezin
... ultimately
char *c   
is better because
 char* a,b,c,d   
is NOT the same as
char *a, *b, *c, *d   


However,
char *a;
char *b;
char *c;
char *d;
is better than
char *a, *b, *c, *d;   
so your argument is moot. Now, I''m not trying to incite a religious war. No!

Share this post


Link to post
Share on other sites
I always preferred char* x to char *x. Mostly it''s because I choose to define "pointer-ness" as an attribute of a type rather than a variable. That is, an int pointer is a different type than an int.

As for the char* a, b, c, d, well that has always annoyed me so I avoid that construction except for rare cases where I do fall back to char *a, *b, *c, *d.


Ultimately it''s a matter of preference. There is no functional or syntactic different between the two.

Share this post


Link to post
Share on other sites
quote:
Original post by Kaezin
 char* a,b,c,d   
is NOT the same as
char *a, *b, *c, *d   



People who code like that have larger style issues to worry about than where they put their asterisks.

Share this post


Link to post
Share on other sites
quote:
Original post by Promit
I always preferred char* x to char *x. Mostly it''s because I choose to define "pointer-ness" as an attribute of a type rather than a variable. That is, an int pointer is a different type than an int.




That makes sense, but then the counter-argument to that is arrays. Definitely you would consider "array-ness" to be part of the type of the variable, but the array notation goes after the variable name:

int array[5]

so you can''t always group all the "type" information in one place.

Share this post


Link to post
Share on other sites

  • Advertisement
×

Important Information

By using GameDev.net, you agree to our community Guidelines, Terms of Use, and Privacy Policy.

We are the game development community.

Whether you are an indie, hobbyist, AAA developer, or just trying to learn, GameDev.net is the place for you to learn, share, and connect with the games industry. Learn more About Us or sign up!

Sign me up!