🚀 go-pugleaf

RetroBBS NetNews Server

Inspired by RockSolid Light RIP Retro Guy

Thread View: comp.os.ms-windows.programmer.tools.mfc
10 messages
10 total messages Started by Vashist Worah Sun, 10 Sep 1995 19:22
Newbie pointer question
#10
Author: Vashist Worah
Date: Sun, 10 Sep 1995 19:22
17 lines
963 bytes
This may seem trivial to veterans here, but I am trying to figure out 
what in the world is the difference in declaring pointers in the two 
different manners illustrated below (VC++ 2.2):

1)	double*  x
2)	double  *x

Of course, referencing pointers in the manner
	*x
yields the value of the variable whose address is stored in the pointer 
x.
Thanks!
----------------------------------------------------------
Vashist Worah        
<vashist@tcsmgmt.com>
My opinions blah blah ...
----------------------------------------------------------
Re: Newbie pointer question
#11
Author: Tanmoy Bhattacharya
Date: Sun, 10 Sep 1995 18:59
40 lines
2433 bytes
In article <9a7cb$d1625.8d@news.tcsmgmt.com>, vashist@tcsmgmt.com (Vashist
Worah) writes: 
|> This may seem trivial to veterans here, but I am trying to figure out 
|> what in the world is the difference in declaring pointers in the two 
|> different manners illustrated below (VC++ 2.2):
|> 
|> 1)	double*  x
|> 2)	double  *x

None.

C is defined in terms of `tokens'. Whitespace forms part of some token (e.g.
string literal or character tokens containing blanks), but its major use is
to separate tokens from each other (see note below). Each of the above two forms
give rise to the same sequence of three tokens: `double',`*' and `x'. The
same set of tokens result from `double*x' with no whitespace whatsoever.

double* x; is however confusing to many beginners: it seems to say that you
are declaring x to be of type `double*'. This is correct, but the obvious
generalization `double* x,y;' declares x to be of type `double*', but y to be
of type `double'. 

double *x; is therefore my preferred way of writing it. double *x,y,*z;
defines x and z to be pointers to doubles, and y to be a double.

Cheers
Tanmoy

Note: To be precise, my statements are wrong. `Tokens' are formed from
`prerocessing tokens', and it is the latter which need to be separated by
whitespace if necessary. Because of the # preprocessing operator and special
meaning of end-of-line in the preprocessing directives, whitespace cannot be
_completely_ ignored when outside of pp-tokens. 
-- 
tanmoy@qcd.lanl.gov(128.165.23.46) DECNET: BETA::"tanmoy@lanl.gov"(1.218=1242)
Tanmoy Bhattacharya O:T-8(MS B285)LANL,NM87544-0285,USA H:#3,802,9 St,NM87545
Others see <gopher://yaleinfo.yale.edu:7700/00/Internet-People/internet-mail>,
<http://alpha.acast.nova.edu/cgi-bin/inmgq.pl>or<ftp://csd4.csd.uwm.edu/pub/
internetwork-mail-guide>. -- <http://nqcd.lanl.gov/people/tanmoy/tanmoy.html>
fax: 1 (505) 665 3003   voice: 1 (505) 665 4733    [ Home: 1 (505) 662 5596 ]
Re: Newbie pointer question
#12
Author: Bernard S. Greenberg
Date: Sun, 10 Sep 1995 21:15
24 lines
1543 bytes
Vashist Worah (vashist@tcsmgmt.com) wrote:
: This may seem trivial to veterans here, but I am trying to figure out 
: what in the world is the difference in declaring pointers in the two 
: different manners illustrated below (VC++ 2.2):

: 1)	double*  x
: 2)	double  *x

: Of course, referencing pointers in the manner
: 	*x
: yields the value of the variable whose address is stored in the pointer 
: x.
: Thanks!

No difference in meaning.  The compiler ignores whitespace around
known operators.  The stylistic difference in meaning would
probably be whether the author thinks that "double *" being a type
(pointer to a double) is more significant than "*x" being a prototype
reference to the object.  Again, there is no difference.

Such questions should be directed to the C language group.

Bernard S. Greenberg
bsg@basistech.com
Re: Newbie pointer question
#13
Author: Mark B. Whipple
Date: Tue, 12 Sep 1995 21:54
21 lines
1608 bytes
vashist@tcsmgmt.com (Vashist Worah) wrote:
>This may seem trivial to veterans here, but I am trying to figure out 
>what in the world is the difference in declaring pointers in the two 
>different manners illustrated below (VC++ 2.2):
>
>1)	double*  x
>2)	double  *x

There is absolutely no difference.

Mark
-- 
-------------------------------------------------------------------------
|mark.whipple@ons.octel.com              |                               |
|Network Systems Sr. Software Engineer   |      Veni,Vidi,Dolavi         |
|Octel Network Services                  |  (I Came,I Saw,I Hacked)      |
|17060 Dallas Parkway, Suite 214         |                               |
|Dallas, Texas 75248-1986                |                               |
|(Voice) (214) 407-7467                  |           `  '                |
|(Fax)   (214) 733-8622                  |            O O                |
--------------------------------------------------000--U--000------------
Re: Newbie pointer question
#14
Author: LeRoy Baxter
Date: Wed, 13 Sep 1995 03:49
24 lines
1306 bytes
vashist@tcsmgmt.com (Vashist Worah) wrote:
>This may seem trivial to veterans here, but I am trying to figure out 
>what in the world is the difference in declaring pointers in the two 
>different manners illustrated below (VC++ 2.2):
>
>1)	double*  x
>2)	double  *x
>
>Of course, referencing pointers in the manner
>	*x
>yields the value of the variable whose address is stored in the pointer 
>x.
>Thanks!
>----------------------------------------------------------
>Vashist Worah        




Simply convention.
 style 2 is C convention
 style 1 is C++ convention. I believe the thought is that "double*"
   more acurately describes the type (pointer) of "x" (the variables'
   name)
Re: Newbie pointer question
#16
Author: Kit Kauffmann
Date: Thu, 14 Sep 1995 15:22
44 lines
2003 bytes
In article <43a4pb$8b4@shellx.best.com> netninja@svpal.org (NetNinja) writes:
>From: netninja@svpal.org (NetNinja)
>Subject: Re: Newbie pointer question
>Date: Thu, 14 Sep 1995 21:05:24 GMT

>vashist@tcsmgmt.com (Vashist Worah) wrote:

>>This may seem trivial to veterans here, but I am trying to figure out 
>>what in the world is the difference in declaring pointers in the two 
>>different manners illustrated below (VC++ 2.2):

>>1)     double*  x
>>2)     double  *x

>>Of course, referencing pointers in the manner
>>       *x
>>yields the value of the variable whose address is stored in the pointer 

>        Well, there is no difference. But, if you are declaring multiple 
>        variables the second style is preferred because it causes less 
>        confusion.
>        if you say 'double*  x, y' that does not mean y is a double pointer, 
>        y is still just a double since the '*' goes with the variable x, 
>        hence it is always better to put it nearer to the variable than the 
>        type 

>        
>        



One could consider this a "religious" issue - I like to define every variable 
on a separate line (leaving room for a comment), and prefer to put the '*' or 
'&' next to the data type, indicating that x is a "pointer to double" or 
whatever...

Standards suck!  Except mine, of course :)



Kit Kauffmann - kitk@mudshark.sunquest.com
AKA 73363,447 (Compu$erve)

Finger me for my public key
Re: Newbie pointer question
#15
Author: NetNinja
Date: Thu, 14 Sep 1995 21:05
23 lines
1240 bytes
vashist@tcsmgmt.com (Vashist Worah) wrote:

>This may seem trivial to veterans here, but I am trying to figure out 
>what in the world is the difference in declaring pointers in the two 
>different manners illustrated below (VC++ 2.2):

>1)	double*  x
>2)	double  *x

>Of course, referencing pointers in the manner
>	*x
>yields the value of the variable whose address is stored in the pointer 

	Well, there is no difference. But, if you are declaring multiple 
	variables the second style is preferred because it causes less 
	confusion.
	if you say 'double*  x, y' that does not mean y is a double pointer, 
	y is still just a double since the '*' goes with the variable x, 
	hence it is always better to put it nearer to the variable than the 
	type 

	
	
Re: Newbie pointer question
#17
Author: Brandon Wallace
Date: Tue, 19 Sep 1995 17:50
18 lines
1267 bytes
On Sun, 10 Sep 1995, Vashist Worah wrote:

-> This may seem trivial to veterans here, but I am trying to figure out 
-> what in the world is the difference in declaring pointers in the two 
-> different manners illustrated below (VC++ 2.2):
-> 
-> 1)	double*  x
-> 2)	double  *x
-> 

THERE IS NO FUNCTIONAL DIFFERENCE

However, some people prefer (1) over (2), some (2) over (1), some don't care.
--
                      Brandon Wallace
            Nicholas | Applegate Capital Management
mailto:bman@criterion.com  http://www.criterion.com/home-pages/brandon
          "I live life face down in the fast lane."
Re: Newbie pointer question
#18
Author: Tim Hollebeek
Date: Wed, 20 Sep 1995 01:21
31 lines
1620 bytes
In article <Pine.SUN.3.91.950919124849.1948C-100000@achilles>,
Brandon Wallace  <brandon@criterion.com> wrote:
>On Sun, 10 Sep 1995, Vashist Worah wrote:
>
>-> This may seem trivial to veterans here, but I am trying to figure out 
>-> what in the world is the difference in declaring pointers in the two 
>-> different manners illustrated below (VC++ 2.2):
>-> 
>-> 1)	double*  x
>-> 2)	double  *x
>-> 
>
>THERE IS NO FUNCTIONAL DIFFERENCE
>
>However, some people prefer (1) over (2), some (2) over (1), some don't care.

Answer 1: Brandon is absolutely right.

Answer 2: You should use 2) because if you use the first, you will
probably think that '*' is part of the type, and do something like:

double* x, y; // declares a pointer to double and a plain old double

at least with the * next to the x, it's a bit more obvious that the *
only applies to the x.

-- 
Tim Hollebeek      | Everything above is a true statement, for sufficiently
PChem Grad Student | false values of true.
Princeton Univ.    | C++ == OOP--
-------------------| tim@handel.princeton.edu  http://wagner.princeton.edu/~tim
Re: Newbie pointer question
#19
Author: Glenn Sills
Date: Fri, 22 Sep 1995 13:29
48 lines
1582 bytes
In article <43nqb8$c2i@cnn.Princeton.EDU>, tim@franck.Princeton.EDUÌ says...
>
>In article <Pine.SUN.3.91.950919124849.1948C-100000@achilles>,
>Brandon Wallace  <brandon@criterion.com> wrote:
>>On Sun, 10 Sep 1995, Vashist Worah wrote:
>>

SNIP...

>>-> 
>>-> 1)  double*  x
>>-> 2)  double  *x
>>-> 
>>
>>THERE IS NO FUNCTIONAL DIFFERENCE
>>
>>However, some people prefer (1) over (2), some (2) over (1), some don't care.
>
>Answer 1: Brandon is absolutely right.
>
>Answer 2: You should use 2) because if you use the first, you will
>probably think that '*' is part of the type, and do something like:
>
>double* x, y; // declares a pointer to double and a plain old double
>

Actually I prefer:

	double* x;
	double y;
	...

because the * IS part of the type....  But it's obviously just a superficial
style thang:-)











>at least with the * next to the x, it's a bit more obvious that the *
>only applies to the x.
>
Thread Navigation

This is a paginated view of messages in the thread with full content displayed inline.

Messages are displayed in chronological order, with the original post highlighted in green.

Use pagination controls to navigate through all messages in large threads.

Back to All Threads