Do you prefer "int* a;" or "int *a;"?

Started by
103 comments, last by DanTheKat 21 years ago
Bjarne Stroustrup has an interesting answer in his FAQ, IIRC. He said that (basically), C++ emphasizes types, so the type should be separated from the variable, i.e.: int* a;

I use int *a. It''s a matter of taste more than anything else. Like indentation or the use of 0 instead of NULL.

Cédric
Advertisement
type *var; // of course!

Primarily because it looks better but I think it makes more sense, as var is primarily a pointer, regardless of what it points to. So, one sees *var, Aha! var is a pointer, lets see what to, Oh! it''s a pointer to a type.

Besides, I''ve always done it that way, and as far as I can remember it has been the most common way. Almost all open-source projects use this convention.

quote:almost all open source projects use this convention

!

that's a lot of projects. have you checked them all? can you tell me the ones that don't?

anyway, I agree with Bjarne

[edited by - petewood on April 7, 2003 10:40:18 AM]
quote:Original post by Soulnafein
An int* type doesn''t exist.


Yes it does.
how much posts about this fucking-stupid quaestion!!
I''m a space-a-holic. I do int * a. and I very rarely define variables int * a, b, c... at all. I consider * and & to be type modifiers, similiar to const or static or volatile... just because they can be represented in one character does not mean that they should be butted up against anything.

Ender_JC
quote:Original post by petewood
that''s a lot of projects. have you checked them all? can you tell me the ones that don''t?
No, and thought of editing my post, but I let it be. However, almost all of the big open-source projects I''ve seen use it, such as Linux and Apache etc., as well as all? GNU-tools. That is, type *var seems to be standard in the "old school *nix"-style.

hahah agreed, if you really want to get this thread heated up, ask THIS question:

Curly brackets, same line, or new line?

I code like this:

if(a == b) {
// stuff;;
};

...versus...

if(a == b)
{
// stuff;;
};

any thoughs anyone? pros/cons?

www.cppnow.com
i use

int* x;

and
if(a == b) {
}

and for the ones with the int* is not a type..

    template<typename T> struct create_a_type { T* pointer;};create_a_type<int>::pointer this_is_a_fucking_pointer_type;    


:D

with typedef templates, it will possibly even be pointer<int> a,b,c; solving all those ambiguiesieiewfrjladfjlöses.



and btw, i for myself prefer to use d (www.digitalmars.com/d/), where it definitely is a type, as

int[] a; is a dynamic int-array, etc.

fuck c, fuck c++, use d:D

"take a look around" - limp bizkit
www.google.com

[edited by - davepermen on April 7, 2003 11:17:29 AM]
If that's not the help you're after then you're going to have to explain the problem better than what you have. - joanusdmentia

My Page davepermen.net | My Music on Bandcamp and on Soundcloud

int*a,*b,*c;

that was unexpected, wasn't it?

--------------------------------

"I'm a half time coder, full time Britney Spears addict"
Targhan

[edited by - targhan on April 7, 2003 11:19:51 AM]
--------------------------------"I'm a half time coder, full time Britney Spears addict" Targhan

This topic is closed to new replies.

Advertisement