All in - pointer declaration
-
Type *p;
or
Type* p;
or even
Type * p;
Me personally, I do whatever is the current company naming conventions.
There is only one Vera Farmiga and Salma Hayek is her prophet! Advertise here – minimum three posts per day are guaranteed.
-
Type *p;
or
Type* p;
or even
Type * p;
Me personally, I do whatever is the current company naming conventions.
There is only one Vera Farmiga and Salma Hayek is her prophet! Advertise here – minimum three posts per day are guaranteed.
(Lights his torch.)
-
Type *p;
or
Type* p;
or even
Type * p;
Me personally, I do whatever is the current company naming conventions.
There is only one Vera Farmiga and Salma Hayek is her prophet! Advertise here – minimum three posts per day are guaranteed.
Have always used this style.
Type* p;
PartsBin an Electronics Part Organizer - An updated version available! JaxCoder.com
-
(Lights his torch.)
Wow, that was low!(-level language)
There is only one Vera Farmiga and Salma Hayek is her prophet! Advertise here – minimum three posts per day are guaranteed.
-
Type *p;
or
Type* p;
or even
Type * p;
Me personally, I do whatever is the current company naming conventions.
There is only one Vera Farmiga and Salma Hayek is her prophet! Advertise here – minimum three posts per day are guaranteed.
type *p;
-
Type *p;
or
Type* p;
or even
Type * p;
Me personally, I do whatever is the current company naming conventions.
There is only one Vera Farmiga and Salma Hayek is her prophet! Advertise here – minimum three posts per day are guaranteed.
I hate the question. The reason being is that the pointer is part of the type intrinsically, and I want to use it that way but C isn't always consistent about it, so it gets weird no matter what you do. Pointer syntax is funky. It just is. There's no amount of style guidelines that will defunk pointers. Ergo, I do whatever the code around me does. Usually I put it with the type but I know I'm hated for that. :laugh:
To err is human. Fortune favors the monsters.
-
Type *p;
or
Type* p;
or even
Type * p;
Me personally, I do whatever is the current company naming conventions.
There is only one Vera Farmiga and Salma Hayek is her prophet! Advertise here – minimum three posts per day are guaranteed.
-
Type *p;
or
Type* p;
or even
Type * p;
Me personally, I do whatever is the current company naming conventions.
There is only one Vera Farmiga and Salma Hayek is her prophet! Advertise here – minimum three posts per day are guaranteed.
Type* p;
Robust Services Core | Software Techniques for Lemmings | Articles
The fox knows many things, but the hedgehog knows one big thing. -
Type *p;
or
Type* p;
or even
Type * p;
Me personally, I do whatever is the current company naming conventions.
There is only one Vera Farmiga and Salma Hayek is her prophet! Advertise here – minimum three posts per day are guaranteed.
Type* p;
"the debugger doesn't tell me anything because this code compiles just fine" - random QA comment "Facebook is where you tell lies to your friends. Twitter is where you tell the truth to strangers." - chriselst "I don't drink any more... then again, I don't drink any less." - Mike Mullikins uncle
-
Type *p;
or
Type* p;
or even
Type * p;
Me personally, I do whatever is the current company naming conventions.
There is only one Vera Farmiga and Salma Hayek is her prophet! Advertise here – minimum three posts per day are guaranteed.
-
Type *p;
or
Type* p;
or even
Type * p;
Me personally, I do whatever is the current company naming conventions.
There is only one Vera Farmiga and Salma Hayek is her prophet! Advertise here – minimum three posts per day are guaranteed.
I prefer
Type* p;
And this only because my compiler gives a wrning when I don't use a parameter in a method:void Method(char x, char* y)
To get rid of the warning I need to do e.g.thisvoid Method(char x, char* /*y*/)
On the other hand if I would do something like this (what I'm not doing ...)const char *a= "a", *b= "b";
Then I get angry because the language itself is not what I would name 'consistent' :laugh: -
Type *p;
or
Type* p;
or even
Type * p;
Me personally, I do whatever is the current company naming conventions.
There is only one Vera Farmiga and Salma Hayek is her prophet! Advertise here – minimum three posts per day are guaranteed.
type* (pointer is part of type) Now moving on: do you do "west const" or "east const"? Standard C++[^] (surely a lot of people - me included - don't want to do productive work today)
Mircea
-
type* (pointer is part of type) Now moving on: do you do "west const" or "east const"? Standard C++[^] (surely a lot of people - me included - don't want to do productive work today)
Mircea
If pointer is part of the type, make it! Make a typedef and use that when declaring variables.
type* x, y;
- is y of a pointer type? You know that it isn't. Lots of problems have been caused by making it appear as if x and y have the same type. (Thankfully, the compiler will catch most such wrongful assumptions.) If you change it to
type y, *x;
- is now the type definition for variable x split into two parts, separated by a variable declaration? If you make a typedef, you have a clear, all-in-one-place type definition, not cluttered up by variables. And you would avoid the risk of someone assuming, in the first example, that x and y are of the same type.
-
If pointer is part of the type, make it! Make a typedef and use that when declaring variables.
type* x, y;
- is y of a pointer type? You know that it isn't. Lots of problems have been caused by making it appear as if x and y have the same type. (Thankfully, the compiler will catch most such wrongful assumptions.) If you change it to
type y, *x;
- is now the type definition for variable x split into two parts, separated by a variable declaration? If you make a typedef, you have a clear, all-in-one-place type definition, not cluttered up by variables. And you would avoid the risk of someone assuming, in the first example, that x and y are of the same type.
trønderen wrote:
Make a typedef and use that when declaring variables.
Amen! Edit: This is one of the (many) early failings of "C". When I write "C" I try to avoid mixing pointer to type and type declarations on the same line and try to keep pointer declarations on their own line. When I do "C++" I'm mostly using stuff like
std::unique_ptr a, b;
If I see two naked pointers in the same declaration, that is most likely a code smell.
Mircea
-
I hate the question. The reason being is that the pointer is part of the type intrinsically, and I want to use it that way but C isn't always consistent about it, so it gets weird no matter what you do. Pointer syntax is funky. It just is. There's no amount of style guidelines that will defunk pointers. Ergo, I do whatever the code around me does. Usually I put it with the type but I know I'm hated for that. :laugh:
To err is human. Fortune favors the monsters.
-
If pointer is part of the type, make it! Make a typedef and use that when declaring variables.
type* x, y;
- is y of a pointer type? You know that it isn't. Lots of problems have been caused by making it appear as if x and y have the same type. (Thankfully, the compiler will catch most such wrongful assumptions.) If you change it to
type y, *x;
- is now the type definition for variable x split into two parts, separated by a variable declaration? If you make a typedef, you have a clear, all-in-one-place type definition, not cluttered up by variables. And you would avoid the risk of someone assuming, in the first example, that x and y are of the same type.
I generally agree with you, but I am not all in on that agreement, if that makes sense. Here's why: You have to look up a typedef to know what it is, and typedefs everywhere make it harder to know what's going on until you can adopt the fundamental lexicon that your typedefs essentially create. That said, everything you wrote is valid. I just think there are places where it might be overkill.
To err is human. Fortune favors the monsters.
-
-
Type* p;
Robust Services Core | Software Techniques for Lemmings | Articles
The fox knows many things, but the hedgehog knows one big thing. -
I agree, but as mentioned in my post below... a thing I don't do but is very common:
const char
*a= "a",
*b= "b";tells us, in this case we are something wrong... :(
This doesn't bother me, because I never do this kind of thing.
Robust Services Core | Software Techniques for Lemmings | Articles
The fox knows many things, but the hedgehog knows one big thing. -
Have always used this style.
Type* p;
PartsBin an Electronics Part Organizer - An updated version available! JaxCoder.com
Me too. Although since I no longer develop in C++, I use:
MyType p;
:) /ravi
My new year resolution: 2048 x 1536 Home | Articles | My .NET bits | Freeware ravib(at)ravib(dot)com