473,403 Members | 2,183 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,403 software developers and data experts.

float* f vs float *f


Hi!
I have used both of these
"float *f"
and
"float* f"

Could someone tell me if one is
preferred and why? Yes, i know both
work but it makes me feel uneasy.

Ditto for:

FILE* fp
vs.
FILE *fp

I would hope to know if there is a standard
and the second is just allowed.

thanks
tom
Nov 8 '08 #1
8 2253
Tom Impelluso <im******@attila.sdsu.edukirjutas:
>
Hi!
I have used both of these
"float *f"
and
"float* f"

Could someone tell me if one is
preferred and why?
It's a style issue. If you declare multiple pointers together, then this
looks better:

float *f, *g, *h;

than

float* f,* g,* h;

On the other hand, if you declare a single thing only, then IMHO

float* f;

looks better than

float *f;

Some people (not me) argue that this gives one reason to the idea to
always declare only a single thing at a time.

YMMV
Paavo

Nov 8 '08 #2
On 2008-11-08 18:35, Paavo Helde wrote:
Tom Impelluso <im******@attila.sdsu.edukirjutas:
>>
Hi!
I have used both of these
"float *f"
and
"float* f"

Could someone tell me if one is
preferred and why?

It's a style issue. If you declare multiple pointers together, then this
looks better:

float *f, *g, *h;

than

float* f,* g,* h;

On the other hand, if you declare a single thing only, then IMHO

float* f;

looks better than

float *f;

Some people (not me) argue that this gives one reason to the idea to
always declare only a single thing at a time.
On the other hand, if you already subscribe to the idea of only one
declaration per line it becomes natural to write "float* f"; type,
whitespace, and then the name.

--
Erik Wikström
Nov 8 '08 #3
Erik Wikström wrote:
On 2008-11-08 18:35, Paavo Helde wrote:
>Tom Impelluso <im******@attila.sdsu.edukirjutas:
Some people (not me) argue that this gives one reason to the idea to
always declare only a single thing at a time.

On the other hand, if you already subscribe to the idea of only one
declaration per line it becomes natural to write "float* f"; type,
whitespace, and then the name.
And then whitespace, '=', whitespace, and initialisation value (possibly
NULL). Initialising each pointer when it is declared is a good practice.

Best wishes,

Zeppe
Nov 8 '08 #4
Tom Impelluso wrote:
Could someone tell me if one is
preferred and why? Yes, i know both
work but it makes me feel uneasy.

Ditto for:

FILE* fp
vs.
FILE *fp

I would hope to know if there is a standard
and the second is just allowed.
There is no standard. It seems to me that the first is more common in C++,
while the second is more common in C, but I've seen both in both languages.
I've also seen a third form, for the undecided:

FILE * fp;

I prefer the first version, since it's more natural to me. The * is part of
the type, and so it belongs to the type and not the name. The inventors of
C, howerver, seem to think that the other variant is more natural, since it
kind of matches with the dereferene operator, and you could say that *fp is
of type FILE.

Nov 8 '08 #5
Rolf Magnus wrote:
The inventors of
C, howerver, seem to think that the other variant is more natural, since it
kind of matches with the dereferene operator, and you could say that *fp is
of type FILE.
That's how I finally grokked pointers in C, wayyyyy back in the day.
Nov 9 '08 #6
Rolf Magnus wrote:
Tom Impelluso wrote:
>Could someone tell me if one is
preferred and why? Yes, i know both
work but it makes me feel uneasy.

Ditto for:

FILE* fp
vs.
FILE *fp

I would hope to know if there is a standard
and the second is just allowed.

There is no standard. It seems to me that the first is more common
in C++, while the second is more common in C, but I've seen both in
both languages. I've also seen a third form, for the undecided:

FILE * fp;

I prefer the first version, since it's more natural to me. The * is
part of the type, and so it belongs to the type and not the name.
The inventors of C, howerver, seem to think that the other variant
is more natural, since it kind of matches with the dereferene
operator, and you could say that *fp is of type FILE.
This fails for C++ references, where

int i = 42;

int& r = i;
and
int &r = i;

are equivalent, but we can't say that &r is of type int.

So to be consistent, you might want to use the style
type-space-name-initializer whenever possible:

int& r = i;

int* p = &i;
Bo Persson

Nov 9 '08 #7
On Nov 8, 11:11*pm, Rolf Magnus <ramag...@t-online.dewrote:
Tom Impelluso wrote:
Could someone tell me if one is preferred and why? *Yes, i
know both work but it makes me feel uneasy.
Ditto for:
FILE* fp
vs.
FILE **fp
I would hope to know if there is a standard and the second
is just allowed.
There is no standard. It seems to me that the first is more
common in C++, while the second is more common in C, but I've
seen both in both languages. I've also seen a third form, for
the undecided:
FILE * fp;
I prefer the first version, since it's more natural to me. The
* is part of the type, and so it belongs to the type and not
the name. The inventors of C, howerver, seem to think that the
other variant is more natural, since it kind of matches with
the dereferene operator, and you could say that *fp is of type
FILE.
That was the original philosophy behind C's declaration syntax;
you specified the basic type, and then an expression which
denoted the basic type. It broke, of course, the day they
introduced typedef's and struct. It broke again when const was
introduced. In sum, it was an experiment that failed, but that
we still have to live with. What it does mean is that we get a
lot of ambiguities between expressions and declarations, and
that there is one more reason to reject more than one
declaration per statement.

--
James Kanze (GABI Software) email:ja*********@gmail.com
Conseils en informatique orientée objet/
Beratung in objektorientierter Datenverarbeitung
9 place Sémard, 78210 St.-Cyr-l'École, France, +33 (0)1 30 23 00 34
Nov 9 '08 #8
On Nov 9, 6:29*am, James Kanze <james.ka...@gmail.comwrote:
On Nov 8, 11:11*pm, Rolf Magnus <ramag...@t-online.dewrote:
Tom Impelluso wrote:
Could someone tell me if one is preferred and why? *Yes, i
know both work but it makes me feel uneasy.
Ditto for:
FILE* fp
vs.
FILE **fp
I would hope to know if there is a standard and the second
is just allowed.
There is no standard. It seems to me that the first is more
common in C++, while the second is more common in C, but I've
seen both in both languages. *I've also seen a third form, for
the undecided:
FILE * fp;
I prefer the first version, since it's more natural to me. The
* is part of the type, and so it belongs to the type and not
the name. The inventors of C, howerver, seem to think that the
other variant is more natural, since it kind of matches with
the dereferene operator, and you could say that *fp is of type
FILE.

That was the original philosophy behind C's declaration syntax;
you specified the basic type, and then an expression which
denoted the basic type. *It broke, of course, the day they
introduced typedef's and struct. *It broke again when const was
introduced. *In sum, it was an experiment that failed, but that
we still have to live with. *What it does mean is that we get a
lot of ambiguities between expressions and declarations, and
that there is one more reason to reject more than one
declaration per statement.

--
James Kanze (GABI Software) * * * * * * email:james.ka...@gmail.com
Conseils en informatique orientée objet/
* * * * * * * * * *Beratung in objektorientierter Datenverarbeitung
9 place Sémard, 78210 St.-Cyr-l'École, France, +33 (0)1 30 23 00 34
Check here: http://www.research.att.com/~bs/bs_faq2.html
see question: Is ``int* p;'' right or is ``int *p;'' right?
Nov 9 '08 #9

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

Similar topics

5
by: Pat | last post by:
Give two double-typed variable X and Y. If (X==Y) is true, then how about the following results: (float(X) > float(Y))? (float(X) < float(Y))? (float(X) >= float(Y))? ( X > float(Y) )? ( X...
14
by: Glen Able | last post by:
Should it be possible to create a custom class, 'Float', which would behave as a drop-in replacement for the builtin float type? As mentioned in another thread, I once tried this in rather a...
16
by: Gerald Lafreniere | last post by:
{ float F=123.456000; F*=1000; // Actually I used a for loop F*=10 three times. printf("%f\n", F); } This will produce something like 123456.00XXXX, where XXXX are garbage digits. Why...
6
by: Dave win | last post by:
Hi all: I'm confused with the expression "(float *())". Book says that this is a cast. But, I have no idea of this expr. why could this expr ignore the variable??? Thanx!!!
9
by: Sisyphus | last post by:
Hi, I have some software that does the following (in an attempt to determine whether the double x, can be represented just as accurately by a float): void test_it(double x) { float y = x;...
11
by: Marc Pelletier | last post by:
Hello, I am having trouble implementing the following callback: CNCSError CECWCompressor::WriteReadLine(UINT32 nNextLine, void **ppInputArray) where ppInputArray is a 3 by x array. The...
20
by: ehabaziz2001 | last post by:
That program does not yield and respond correctly espcially for the pointers (*f),(*i) in print_divide_meter_into(&meter,&yds,&ft,&ins); /*--------------pnt02own.c------------ ---1 inch = 2.51...
8
by: vjnr83 | last post by:
Hi, I have a doubt: what is the difference between float **p and float *p? Thanks in advance, Vijay
13
by: Shirsoft | last post by:
I have a 32 bit intel and 64 bit AMD machine. There is a rounding error in the 8th digit. Unfortunately because of the algorithm we use, the errors percolate into higher digits. C++ code is...
3
by: Arnie | last post by:
Folks, We ran into a pretty significant performance penalty when casting floats. We've identified a code workaround that we wanted to pass along but also was wondering if others had experience...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
0
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
0
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
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
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...
0
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...
0
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...

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.