Jump to content
  • Advertisement
Sign in to follow this  
Madolite

Pointers: "type* var" versus "type *var"

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

What conventions do you guys use for pointers, when and why?

type *name and type &name
- OR -
type* name and type& name

I'd like to hear what you guys like to do and why you prefer one thing over another. I'm asking these weird questions because I'm self-taught and experience a lot of people using either convention or even both, depending on various personal criterias. My eyes are practically bleeding from all the interchanged uses.

And then you got type** name and T&& name. Aaaargh!

Thanks. smile.png

Edited by Madolite

Share this post


Link to post
Share on other sites
Advertisement

...higher danger of accidentally going 'type* var1, var2;' and not declaring what you expect to declare. I am however strongly opposed to declaring multiple variables in one line..

I prefer a linebreak between variables as well.

Edited by Madolite

Share this post


Link to post
Share on other sites

I do whatever the nearby code does in general. next to the type, next to the name, or even with space on both sides, it really doesn't matter to me.

 

I tend to slightly prefer putting the * or & next to the variable.

Share this post


Link to post
Share on other sites

Personally I use type* var, because I feel like it's part of the type and I find it aesthetically more pleasing, but one could argue it's more clear and more consistent to write it next to the variable name because:

int* a, b;

Here a is a pointer, but b is not.

 

Put next to the variable name makes more sense here:

int *a, b;

This makes it clearer that a is a pointer and b is not and it's also more consistent in case b were to be a pointer.

Share this post


Link to post
Share on other sites

 My eyes are practically bleeding from all the interchanged uses\

 

The sooner you get used to this the better; in the grand scheme of things this is yet another one of those pointless decisions that only matters because it's important to make a decision and stick to it.

 

I'll get used to it, but it's just nice to get some explicit opinions on the matter. smile.png

Edited by Madolite

Share this post


Link to post
Share on other sites

type *var

 

always.

 

more uniform syntax for stuff like

 

int a,b;

int *a,b;

 

vs

 

int a,b;

int* a;

int b;

 

also, that's the format my macro processor expects. <g>

Share this post


Link to post
Share on other sites
Sign in to follow this  

  • 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!