Jump to content
  • Advertisement

Archived

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

ELS1

do u prefer int* i OR int *i??

This topic is 6183 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

i typically use: int *i; & void swap(int &a, int &b) BUT in my book it says that Stroustrup introduced this other style and many people adopted it: int* i ; & void swap(int& a, int& b) i know there is no difference..but a matter of style....but what do you like to use and why?

Share this post


Link to post
Share on other sites
Advertisement
Guest Anonymous Poster
I tend to use int *i;

Makes it easier to read if i have more on a single line like so:

char *t, m;

much simpler to read than:

char* t, m;

The second one makes it looks like both are going to be pointers, while only the first one will be. It''s the variable that is getting assigned to be a pointer, not the "type", so why would you "attach" the * or & to the type, and not the variable? It just makes things confusing, where if you attached it to the variable name, there is no confusion.

Billy - BillyB@mrsnj.com

Share this post


Link to post
Share on other sites
i prefer "int *i".

however with references i do the opposite; i.e. "const String& s".

To the vast majority of mankind, nothing is more agreeable than to escape the need for mental exertion... To most people, nothing is more troublesome than the effort of thinking.

Share this post


Link to post
Share on other sites
int *i

i is the pointer. The int is just the type the pointer points to.

Edited by - granat on January 11, 2002 1:53:46 PM

Share this post


Link to post
Share on other sites
I usually use

int* i;

and

void afunction(int& one, int& two);

For me it is easier to read that way.
I usually don't do stuff like

int *i, m; Because to me thats just confusing to a reader
no matter how you do it.

EDIT: The reason I do that is because I read them as "___ a pointer to a ____" So in this case, "i is a pointer to an int".

Edited by - xgalaxy on January 11, 2002 1:58:28 PM

Share this post


Link to post
Share on other sites
I do "int* i" because the type of the variable ''i'' is ''int*''. Same for references.

I don''t do "char* i, m". I do "char* i; char m;" because ''i'' and ''m'' do not have the same type.

The identation of brackets is just a matter of taste. But as for * I think there is more than just taste because it defines the type of the var so it must not be confusing with other variables.

----------------
Blaster
Computer game programmer and part time human being
Strategy First - http://www.strategyfirst.com
BlasterSoft - http://www.blastersoft.com

Share this post


Link to post
Share on other sites
Guest Anonymous Poster
Definitely int *i. As mentioned above, the ''*'' is a property of the variable, not of the type. If you want an abstracted pointer type, you can still create something like MS''s LPxxx stuff. But writing int* blah is just confusing.

- AH

Share this post


Link to post
Share on other sites
I don't think the '*' makes the property of anything. Doing 'int* i;' and 'int i;" make two variables of two different types.

What do you do with functions that return pointers? I put the '*' beside the 'char' because that's the type of the variable the function returns. Putting the '*' beside the function name doesn't seem good and according to the last AP the '*' would then be a property of the function or something.

I have read some people make a difference when writing the return type of a function and the type of a variable (when they are pointers). I don't see any difference, so I write them the same way.

EDIT - we must not let this thread become a war, so I will stop posting my tastes/opinions.

----------------
Blaster
Computer game programmer and part time human being
Strategy First - http://www.strategyfirst.com
BlasterSoft - http://www.blastersoft.com

Edited by - Blaster on January 11, 2002 2:14:22 PM

Share this post


Link to post
Share on other sites
Guest Anonymous Poster
I use "int* p" because p is an "int*".

Stroustrup also stresses one declaration per line so things like "int* p, i" would never happen if you always follow his style recommendations.

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.

GameDev.net is your game development community. Create an account for your GameDev Portfolio and participate in the largest developer community in the games industry.

Sign me up!