473,509 Members | 12,711 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

pointer representation: style or substance?

Is there any difference between:

char *pointer;
char* pointer;

Is the choice one of aesthetics or does this denote real differences?

Zach

Feb 19 '07 #1
23 1626
On Feb 19, 1:06 pm, "Zach" <net...@gmail.comwrote:
Is there any difference between:

char *pointer;
char* pointer;

Is the choice one of aesthetics or does this denote real differences?
No real difference; the choice is one of aesthetics only.

However,
char* pointer;
can mislead a neophyte, in that
char* pointer1, pointer2;
may be mis-read as
pointer1 is a pointer to char
pointer2 is a pointer to char
rather than
pointer1 is a pointer to char
pointer2 is a char

IMHO,
char *pointer;
is clearer (to the neophyte), in that there is less chance of
misreading
char *pointer1, pointer2;
as above.

HTH
--
Lew

Feb 19 '07 #2
On Feb 19, 1:13 pm, "Lew Pitcher" <lpitc...@sympatico.cawrote:
>
No real difference; the choice is one of aesthetics only.
Thanks Lew.

Zach
Feb 19 '07 #3

"Zach" <ne****@gmail.comwrote in message
news:11*********************@v45g2000cwv.googlegro ups.com...
Is there any difference between:

char *pointer;
char* pointer;

Is the choice one of aesthetics or does this denote real differences?
There is no difference; it is just a matter of personal style.
However, the second style can be misleading, especially to new
programmers:

char* ptr1, ptr2;

Here, ptr1 is a pointer to char, but ptr1 is just a char.

char *x, y;
The above style makes it more clear that x is a pointer but y is not.

--
Fred L. Kleinschmidt
Feb 19 '07 #4

"Fred Kleinschmidt" <fr******************@boeing.comwrote in message
news:JD********@news.boeing.com...
>
"Zach" <ne****@gmail.comwrote in message
news:11*********************@v45g2000cwv.googlegro ups.com...
>Is there any difference between:

char *pointer;
char* pointer;

Is the choice one of aesthetics or does this denote real differences?

There is no difference; it is just a matter of personal style.
However, the second style can be misleading, especially to new
programmers:

char* ptr1, ptr2;

Here, ptr1 is a pointer to char, but ptr1 is just a char.
ptr2 you mean :)

Feb 19 '07 #5
Fred Kleinschmidt wrote:
"Zach" <ne****@gmail.comwrote in message
news:11*********************@v45g2000cwv.googlegro ups.com...
>>Is there any difference between:

char *pointer;
char* pointer;

Is the choice one of aesthetics or does this denote real differences?


There is no difference; it is just a matter of personal style.
However, the second style can be misleading, especially to new
programmers:

char* ptr1, ptr2;

Here, ptr1 is a pointer to char, but ptr1 is just a char.

char *x, y;
The above style makes it more clear that x is a pointer but y is not.
The argument becomes moot if you stick to one variable declaration per line.

--
Ian Collins.
Feb 19 '07 #6

"Zach" <ne****@gmail.comwrote in message
Is there any difference between:

char *pointer;
char* pointer;

Is the choice one of aesthetics or does this denote real differences?
C odesn't fuss too much about whitespace.

However char *pointer is better and would be the required form if whitespace
ever became standardised.
You might wonder why * is used both to dereference and to declare a pointer.
When you use the second form to declare, it makes sense in a formal grammary
sort of way.
>

Feb 19 '07 #7
Malcolm McLean wrote:
"Zach" <ne****@gmail.comwrote in message
>>Is there any difference between:

char *pointer;
char* pointer;

Is the choice one of aesthetics or does this denote real differences?

C odesn't fuss too much about whitespace.

However char *pointer is better and would be the required form if whitespace
ever became standardised.
Define better!
You might wonder why * is used both to dereference and to declare a pointer.
When you use the second form to declare, it makes sense in a formal grammary
sort of way.
Doesn't this contradict your first paragraph?

--
Ian Collins.
Feb 19 '07 #8
boa
Malcolm McLean wrote:
"Zach" <ne****@gmail.comwrote in message
>Is there any difference between:

char *pointer;
char* pointer;

Is the choice one of aesthetics or does this denote real differences?
C odesn't fuss too much about whitespace.

However char *pointer is better and would be the required form if whitespace
ever became standardised.
You might wonder why * is used both to dereference and to declare a pointer.
When you use the second form to declare, it makes sense in a formal grammary
sort of way.
dmr describes it as "An accident of syntax" in
http://cm.bell-labs.com/cm/cs/who/dmr/chist.html ;-)

Boa
Feb 19 '07 #9
Zach wrote:
>
Is there any difference between:

char *pointer;
char* pointer;

Is the choice one of aesthetics or does this denote real differences?
In C we normally use the first version. You can see the reason in:

char* a, b, c;

where a is of type char*, while b and c are of type char. This is
also the reason many people (but not me) object to declaring more
than one object per line. If you want all the variable to be of
type char*, you need to declare:

char *a, *b, *c;

--
<http://www.cs.auckland.ac.nz/~pgut001/pubs/vista_cost.txt>
<http://www.securityfocus.com/columnists/423>

"A man who is right every time is not likely to do very much."
-- Francis Crick, co-discover of DNA
"There is nothing more amazing than stupidity in action."
-- Thomas Matthews
Feb 20 '07 #10
Fred Kleinschmidt <fr******************@boeing.comwrote:
There is no difference; it is just a matter of personal style.
However, the second style can be misleading, especially to new
programmers:
char* ptr1, ptr2;
Although the specifics are different, the Java IDE I use seems to
agree that multiple definitions per line are a poor stylistic choice.
Brevity may be the soul of wit, but such is not the species of
cleverness demanded of a good programmer.

--
C. Benson Manica | I *should* know what I'm talking about - if I
cbmanica(at)gmail.com | don't, I need to know. Flames welcome.
Feb 20 '07 #11
Ian Collins <ia******@hotmail.comwrote:
Fred Kleinschmidt wrote:
There is no difference; it is just a matter of personal style.
However, the second style can be misleading, especially to new
programmers:

char* ptr1, ptr2;

Here, ptr1 is a pointer to char, but ptr1 is just a char.

char *x, y;
The above style makes it more clear that x is a pointer but y is not.

The argument becomes moot if you stick to one variable declaration per line.
True, but then you have to reserve the first sheet of A4 for your
variable declarations.

Richard
Feb 20 '07 #12
Richard Bos wrote:
Ian Collins <ia******@hotmail.comwrote:

>>Fred Kleinschmidt wrote:
>>>There is no difference; it is just a matter of personal style.
However, the second style can be misleading, especially to new
programmers:

char* ptr1, ptr2;

Here, ptr1 is a pointer to char, but ptr1 is just a char.

char *x, y;
The above style makes it more clear that x is a pointer but y is not.

The argument becomes moot if you stick to one variable declaration per line.

True, but then you have to reserve the first sheet of A4 for your
variable declarations.
Not if you keep your functions short.

--
Ian Collins.
Feb 20 '07 #13
Ian Collins <ia******@hotmail.comwrote:
True, but then you have to reserve the first sheet of A4 for your
variable declarations.
Not if you keep your functions short.
IMHO, a function with enough variables to fill a sheet of A4 is in need
of refactoring.

--
C. Benson Manica | I *should* know what I'm talking about - if I
cbmanica(at)gmail.com | don't, I need to know. Flames welcome.
Feb 20 '07 #14
On Feb 20, 4:30 am, r...@hoekstra-uitgeverij.nl (Richard Bos) wrote:
>
True, but then you have to reserve the first sheet of A4 for your
variable declarations.
Hoi Richard,

Or for us Americans the first sheet of Letter ;-)

Zach

Feb 21 '07 #15
Ian Collins <ia******@hotmail.comwrote:
Richard Bos wrote:
Ian Collins <ia******@hotmail.comwrote:
>Fred Kleinschmidt wrote:

char *x, y;
The above style makes it more clear that x is a pointer but y is not.

The argument becomes moot if you stick to one variable declaration per line.
True, but then you have to reserve the first sheet of A4 for your
variable declarations.
Not if you keep your functions short.
Well, I may have been exaggerating a little.

However, I do think that

int start_x,start_y,start_z, end_x,end_y,end_z, *tx,*ty,*tz;

is at least as clear as, and a lot more friendly on the browsing than,

int start_x;
int start_y;
int start_z;
int end_x;
int end_y;
int end_z;
int *tx;
int *ty;
int *tz;

IMO, one should group things together which belong together, and keep
things separate which have no connection with one another. This goes for
declarations as much as for nuts and bolts. (As for keeping things
separate, I would not recommend doing this:

int start_x,start_y,start_z, buffersize, age;

That's best split onto three lines.)

Richard
Feb 22 '07 #16
rl*@hoekstra-uitgeverij.nl (Richard Bos) writes:
[...]
Well, I may have been exaggerating a little.

However, I do think that

int start_x,start_y,start_z, end_x,end_y,end_z, *tx,*ty,*tz;

is at least as clear as, and a lot more friendly on the browsing than,

int start_x;
int start_y;
int start_z;
int end_x;
int end_y;
int end_z;
int *tx;
int *ty;
int *tz;
[...]

I might write that as:

int start_x, start_y, start_z;
int end_x, end_y, end_z;
int *tx, *ty, *tz;

or maybe even:

int start_x, start_y, start_z;
int end_x, end_y, end_z;
int *tx, *ty, *tz;

Or, better yet, I might wrap start, end, and t into a struct. If your
code, even a single line of declarations, is long and redundant, often
(but not always) the best solution is to find and exploit the
redundancy an shorten the code.

--
Keith Thompson (The_Other_Keith) ks***@mib.org <http://www.ghoti.net/~kst>
San Diego Supercomputer Center <* <http://users.sdsc.edu/~kst>
We must do something. This is something. Therefore, we must do this.
Feb 22 '07 #17
Keith Thompson wrote:
>
I might write that as:

int start_x, start_y, start_z;
int end_x, end_y, end_z;
int *tx, *ty, *tz;

or maybe even:

int start_x, start_y, start_z;
int end_x, end_y, end_z;
int *tx, *ty, *tz;

Or, better yet, I might wrap start, end, and t into a struct. If your
code, even a single line of declarations, is long and redundant, often
(but not always) the best solution is to find and exploit the
redundancy an shorten the code.
A big +1 to that.

--
Ian Collins.
Feb 22 '07 #18
Keith Thompson <ks***@mib.orgwrote:
rl*@hoekstra-uitgeverij.nl (Richard Bos) writes:
[...]
Well, I may have been exaggerating a little.

However, I do think that

int start_x,start_y,start_z, end_x,end_y,end_z, *tx,*ty,*tz;

is at least as clear as, and a lot more friendly on the browsing than,

int start_x;
int start_y;
int start_z;
int end_x;
int end_y;
int end_z;
int *tx;
int *ty;
int *tz;
[...]

I might write that as:

int start_x, start_y, start_z;
int end_x, end_y, end_z;
int *tx, *ty, *tz;

or maybe even:

int start_x, start_y, start_z;
int end_x, end_y, end_z;
int *tx, *ty, *tz;
Good idea. Even so, you have several declarations on a line. More to the
point, you still need to include the pointer declarators for ty and tx:

int* tx, ty, tz;

would be wrong.

Richard
Feb 23 '07 #19
rl*@hoekstra-uitgeverij.nl (Richard Bos) writes:
Keith Thompson <ks***@mib.orgwrote:
>rl*@hoekstra-uitgeverij.nl (Richard Bos) writes:
[...]
>I might write that as:

int start_x, start_y, start_z;
int end_x, end_y, end_z;
int *tx, *ty, *tz;

or maybe even:

int start_x, start_y, start_z;
int end_x, end_y, end_z;
int *tx, *ty, *tz;

Good idea. Even so, you have several declarations on a line. More to the
point, you still need to include the pointer declarators for ty and tx:

int* tx, ty, tz;

would be wrong.
Yes. (That's not a mistake I'd make.)

--
Keith Thompson (The_Other_Keith) ks***@mib.org <http://www.ghoti.net/~kst>
San Diego Supercomputer Center <* <http://users.sdsc.edu/~kst>
We must do something. This is something. Therefore, we must do this.
Feb 23 '07 #20
Keith Thompson <ks***@mib.orgwrote:
rl*@hoekstra-uitgeverij.nl (Richard Bos) writes:
Keith Thompson <ks***@mib.orgwrote:
rl*@hoekstra-uitgeverij.nl (Richard Bos) writes:
[...]
I might write that as:

int start_x, start_y, start_z;
int end_x, end_y, end_z;
int *tx, *ty, *tz;

or maybe even:

int start_x, start_y, start_z;
int end_x, end_y, end_z;
int *tx, *ty, *tz;
Good idea. Even so, you have several declarations on a line. More to the
point, you still need to include the pointer declarators for ty and tx:

int* tx, ty, tz;

would be wrong.

Yes. (That's not a mistake I'd make.)
Well, no, because you use (as evidenced above) the Right Way of writing
declarations, not the Wrong Way.

(Your turn to recycle this thread, Ian.)

Richard
Feb 26 '07 #21
Richard Bos wrote:
Keith Thompson <ks***@mib.orgwrote:

>>rl*@hoekstra-uitgeverij.nl (Richard Bos) writes:
>>>Keith Thompson <ks***@mib.orgwrote:

rl*@hoekstra-uitgeverij.nl (Richard Bos) writes:

[...]
>>>>I might write that as:

int start_x, start_y, start_z;
int end_x, end_y, end_z;
int *tx, *ty, *tz;

or maybe even:

int start_x, start_y, start_z;
int end_x, end_y, end_z;
int *tx, *ty, *tz;

Good idea. Even so, you have several declarations on a line. More to the
point, you still need to include the pointer declarators for ty and tx:

int* tx, ty, tz;

would be wrong.

Yes. (That's not a mistake I'd make.)


Well, no, because you use (as evidenced above) the Right Way of writing
declarations, not the Wrong Way.

(Your turn to recycle this thread, Ian.)
The problem would exist if you only put one declaration per line!

--
Ian Collins.
Feb 26 '07 #22
Ian Collins wrote:
Richard Bos wrote:
>>Keith Thompson <ks***@mib.orgwrote:
>>>rl*@hoekstra-uitgeverij.nl (Richard Bos) writes:
Keith Thompson <ks***@mib.orgwrote:
>rl*@hoekstra-uitgeverij.nl (Richard Bos) writes:

[...]
>I might write that as:
>
int start_x, start_y, start_z;
int end_x, end_y, end_z;
int *tx, *ty, *tz;
>
>or maybe even:
>
int start_x, start_y, start_z;
int end_x, end_y, end_z;
int *tx, *ty, *tz;

Good idea. Even so, you have several declarations on a line. More to the
point, you still need to include the pointer declarators for ty and tx:

int* tx, ty, tz;

would be wrong.

Yes. (That's not a mistake I'd make.)


Well, no, because you use (as evidenced above) the Right Way of writing
declarations, not the Wrong Way.

(Your turn to recycle this thread, Ian.)

The problem would exist if you only put one declaration per line!
Oops, too early - "The problem would not exist"

--
Ian Collins.
Feb 26 '07 #23
Keith Thompson wrote:
>
rl*@hoekstra-uitgeverij.nl (Richard Bos) writes:
[...]
Well, I may have been exaggerating a little.

However, I do think that

int start_x,start_y,start_z, end_x,end_y,end_z, *tx,*ty,*tz;

is at least as clear as, and a lot more friendly on the browsing than,

int start_x;
int start_y;
int start_z;
int end_x;
int end_y;
int end_z;
int *tx;
int *ty;
int *tz;
[...]

I might write that as:

int start_x, start_y, start_z;
int end_x, end_y, end_z;
int *tx, *ty, *tz;

or maybe even:

int start_x, start_y, start_z;
int end_x, end_y, end_z;
int *tx, *ty, *tz;
I'll choose

int start_x, end_x, *tx;
int start_y, end_y, *ty;
int start_z, end_z, *tz;

--
DPS
Feb 28 '07 #24

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

11
437
by: pemo | last post by:
Ambiguous? I have a student who's asked me to explain the following std text (esp. the footnote). 6.2.6.1.5 Certain object representations need not represent a value of the object type. If...
0
7137
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
0
7349
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...
0
7417
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...
1
7074
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows...
0
7506
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each...
1
5063
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome a new...
0
4734
by: conductexam | last post by:
I have .net C# application in which I am extracting data from word file and save it in database particularly. To store word all data as it is I am converting the whole word file firstly in HTML and...
0
1572
by: 6302768590 | last post by:
Hai team i want code for transfer the data from one system to another through IP address by using C# our system has to for every 5mins then we have to update the data what the data is updated ...
1
780
muto222
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.