By using this site, you agree to our updated Privacy Policy and our Terms of Use. Manage your Cookies Settings.
446,194 Members | 888 Online
Bytes IT Community
+ Ask a Question
Need help? Post your question and get tips & solutions from a community of 446,194 IT Pros & Developers. It's quick & easy.

A religious question: int* i; /*or*/ int *i;?

P: n/a
I'm reading through Kyle Loudon's _C++_Pocket_Reference_ for the sake of
review. He uses the notational form used by Kernighan and Ritchie in
declaring pointers (and by extension references). That is, the '*' or '&'
is placed directly preceeding the identifier being declared. Stroustrup
consistently uses the alternative form of placing the '*' or '&'
immediately after the type name of the object to be pointed to or
referenced.

I much prefer Stroustrup's style because it seems to be grammatically more
accurate, and does not give the impression that the '*' or '&' is being
used as an operator in the declaration.

I have seen a third approach of putting whitespace on either side of the '*'
or '&'. To me this is simply equivocating non-committal.

So I have two questions about this. First which do you prefer and why?
Second, what is the formal grammatical decomposition of a declaration of
the form:

int* i; ?

Yes, I am asking this as both a serious question, and tongue-in-cheek. ;)
I'm just curious what others have to say about it. What style do other
notable authorities use?
--
STH
Hatton's Law: "There is only One inviolable Law"
KDevelop: http://www.kdevelop.org SuSE: http://www.suse.com
Mozilla: http://www.mozilla.org
Jul 22 '05 #1
Share this Question
Share on Google+
30 Replies


P: n/a
Hello Steven,
On Thu, 26 Aug 2004 02:11:22 -0400, Steven T. Hatton wrote:
I much prefer Stroustrup's style because it seems to be grammatically more
accurate, and does not give the impression that the '*' or '&' is being
used as an operator in the declaration.

I also prefer Stroutsroups style, but there is a pitfall with doing
this. Declare
int* i,j;
and you will get
int* i; // as excpected
int j; // an int and not a pointer to int

Regards
Carsten
--
mail<AT>carsten-spiess.de
Jul 22 '05 #2

P: n/a
Steven T. Hatton wrote:
I'm reading through Kyle Loudon's _C++_Pocket_Reference_ for the sake of
review. He uses the notational form used by Kernighan and Ritchie in
declaring pointers (and by extension references). That is, the '*' or '&'
is placed directly preceeding the identifier being declared. Stroustrup
consistently uses the alternative form of placing the '*' or '&'
immediately after the type name of the object to be pointed to or
referenced.

I much prefer Stroustrup's style because it seems to be grammatically more
accurate, and does not give the impression that the '*' or '&' is being
used as an operator in the declaration.

I have seen a third approach of putting whitespace on either side of the '*'
or '&'. To me this is simply equivocating non-committal.

So I have two questions about this. First which do you prefer and why?
Second, what is the formal grammatical decomposition of a declaration of
the form:

int* i; ?

Yes, I am asking this as both a serious question, and tongue-in-cheek. ;)
I'm just curious what others have to say about it. What style do other
notable authorities use?

Consider this:
int *p, i;
and

int* p, i;

i in both cases is an int, so placing the asterisk close to int may be
confusing.
On the other hand, in the first approach * goes with the identifier p
which is a pointer.
So I consider the first one to be the more "rational correct". Also how
would be the second approach in the case:
int *p, i, *r; ?

int* p, i, * r;

The second looks like idiotic to me. :-)


Regards,

Ioannis Vranos

http://www23.brinkster.com/noicys
Jul 22 '05 #3

P: n/a
Steven T. Hatton wrote:
....

Yes, I am asking this as both a serious question, and tongue-in-cheek. ;)
I'm just curious what others have to say about it. What style do other
notable authorities use?


There is only 1 right way ! :-)

http://tinyurl.com/4bnb7

http://groups.google.com/groups?hl=e...andrew.cmu.edu
Jul 22 '05 #4

P: n/a
Carsten Spie wrote:
Hello Steven,
On Thu, 26 Aug 2004 02:11:22 -0400, Steven T. Hatton wrote:
I much prefer Stroustrup's style because it seems to be grammatically more
accurate, and does not give the impression that the '*' or '&' is being
used as an operator in the declaration.

I also prefer Stroutsroups style, but there is a pitfall with doing
this. Declare
int* i,j;
and you will get
int* i; // as excpected
int j; // an int and not a pointer to int

Regards
Carsten


I realized that after I sent the original message. I don't belive it will
change my style, but it certainly gives weight to the K&R choice.
--
"[M]y dislike for the preprocessor is well known. Cpp is essential in C
programming, and still important in conventional C++ implementations, but
it is a hack, and so are most of the techniques that rely on it. ...I think
the time has come to be serious about macro-free C++ programming." -B.S.
Jul 22 '05 #5

P: n/a
In message <cg**********@ulysses.noc.ntua.gr>, Ioannis Vranos
<iv*@guesswh.at.grad.com> writes
Steven T. Hatton wrote:
I'm reading through Kyle Loudon's _C++_Pocket_Reference_ for the sake of
review. He uses the notational form used by Kernighan and Ritchie in
declaring pointers (and by extension references). That is, the '*' or '&'
is placed directly preceeding the identifier being declared. Stroustrup
consistently uses the alternative form of placing the '*' or '&'
immediately after the type name of the object to be pointed to or
referenced.
I much prefer Stroustrup's style because it seems to be
grammatically more
accurate, and does not give the impression that the '*' or '&' is being
used as an operator in the declaration. I have seen a third
approach of putting whitespace on either side of the '*'
or '&'. To me this is simply equivocating non-committal. So I have
two questions about this. First which do you prefer and why? Second,
what is the formal grammatical decomposition of a declaration of
the form:
int* i; ?
declaration: block-declaration
block-declaration: simple-declaration
simple-declaration: decl-specifier-seq init-declarator-list ";"
decl-specifier-seq: decl-specifier
decl-specifier: type-specifier
type-specifier: simple-type-specifier
simpl-type-specifier: "int"
init-declarator-list: init-declarator
init-declarator: declarator
declarator: ptr-operator declarator
ptr-operator: "*"
declarator: direct-declarator
direct-declarator: declarator-id
declarator-id: id-expression
id-expression: unqualified-id
unqualified_id: identifier
identifier: nondigit
nondigit: "i"

(listing just the relevant branches, and omitting anything subscripted
"opt" that isn't actually used.)
Yes, I am asking this as both a serious question, and
tongue-in-cheek. ;)
I'm just curious what others have to say about it. What style do other
notable authorities use?

Consider this:
int *p, i;

and

int* p, i;

i in both cases is an int, so placing the asterisk close to int may be
confusing.

On the other hand, in the first approach * goes with the identifier p
which is a pointer.

So I consider the first one to be the more "rational correct". Also how
would be the second approach in the case:

int *p, i, *r; ?

int* p, i, * r;


If you only declare -- and initialise -- variables at the point of first
use, most of these multiple declarations vanish, so the question doesn't
arise ;-).

--
Richard Herring
Jul 22 '05 #6

P: n/a
"Steven T. Hatton" wrote:

I'm reading through Kyle Loudon's _C++_Pocket_Reference_ for the sake of
review. He uses the notational form used by Kernighan and Ritchie in
declaring pointers (and by extension references). That is, the '*' or '&'
is placed directly preceeding the identifier being declared. Stroustrup
consistently uses the alternative form of placing the '*' or '&'
immediately after the type name of the object to be pointed to or
referenced.

I much prefer Stroustrup's style because it seems to be grammatically more
accurate, and does not give the impression that the '*' or '&' is being
used as an operator in the declaration.

I have seen a third approach of putting whitespace on either side of the '*'
or '&'. To me this is simply equivocating non-committal.

So I have two questions about this. First which do you prefer and why?
Second, what is the formal grammatical decomposition of a declaration of
the form:

int* i; ?

Yes, I am asking this as both a serious question, and tongue-in-cheek. ;)
I'm just curious what others have to say about it. What style do other
notable authorities use?


Well then, I'm 'non'committal' --

Space on both sides, makes it immediately obvious (to me) what is going on,
doesn't crowd the type or name, and I never have multiple declarations on one
line.

Been doing this since I started programming and never had a problem.
Jul 22 '05 #7

P: n/a

"Steven T. Hatton" <su******@setidava.kushan.aa> wrote in message
news:EN********************@speakeasy.net...
I'm reading through Kyle Loudon's _C++_Pocket_Reference_ for the sake of
review. He uses the notational form used by Kernighan and Ritchie in
declaring pointers (and by extension references). That is, the '*' or '&'
is placed directly preceeding the identifier being declared. Stroustrup
consistently uses the alternative form of placing the '*' or '&'
immediately after the type name of the object to be pointed to or
referenced.

I much prefer Stroustrup's style because it seems to be grammatically more
accurate, and does not give the impression that the '*' or '&' is being
used as an operator in the declaration.

I have seen a third approach of putting whitespace on either side of the '*' or '&'. To me this is simply equivocating non-committal.

So I have two questions about this. First which do you prefer and why?
Second, what is the formal grammatical decomposition of a declaration of
the form:

int* i; ?

Yes, I am asking this as both a serious question, and tongue-in-cheek. ;)
I'm just curious what others have to say about it. What style do other
notable authorities use?


This has been discussed so many times it's ridiculous. But, seeing as I'm
the ultimate "notable authority" (from my perspective, anyway :-)), I
declare that the CORRECT way is to put the * with the type, not with the
variable name. Plus, NEVER declare more than one variable on one line!
(That prevents any chance of confusion, and makes finding the variable
you're looking for much easier.)

One other thing I do (which I just know pisses some others off) is to always
precede pointer variable names with the small letter 'p', as in pHead. It's
the only time I use that weird hungarian notation, but it really helps me
recognize pointers from non-pointers. (But that makes me wonder...should a
pointer to a pointer to a Head then be a ppHead? Sorry, bad pun.)

"But that's just my opinion. I could be wrong."

-Howard

Jul 22 '05 #8

P: n/a
Julie wrote:
"Steven T. Hatton" wrote:
int* i; ?

Space on both sides, makes it immediately obvious (to me) what is going on, doesn't crowd the type or name, and I never have multiple declarations on one line.

Been doing this since I started programming and never had a problem.


Absitively. Space on both sides: int * i.

I'm visually impaired - especially when I program while f---ed up - so every
little visual cue helps.

--
Phlip
http://industrialxp.org/community/bi...UserInterfaces

Jul 22 '05 #9

P: n/a
* Phlip:
* Julie:

* Steven T. Hatton:

int* i; ?


Space on both sides, makes it immediately obvious (to me) what is going
on,doesn't crowd the type or name, and I never have multiple declarations on
one line.

Been doing this since I started programming and never had a problem.


Absitively. Space on both sides: int * i.

I'm visually impaired - especially when I program while f---ed up - so every
little visual cue helps.


Although Australian farmers have found that new technology allows
f--king while farming, see <url: http://tinyurl.com/5btbx>, it's generally
not recommended to f--k while programming, especially not in C++, even if
you have space on both sides and can rely on visual cues.

--
A: Because it messes up the order in which people normally read text.
Q: Why is it such a bad thing?
A: Top-posting.
Q: What is the most annoying thing on usenet and in e-mail?
Jul 22 '05 #10

P: n/a
Sorry about the tinyurl, the URL it refers only works as a link from
certain web-pages such as Google because the web-page provider (news.24.com,
don't use it, they're incompetent and/or uncaring folks) has access control.

Same article elsewhere, namely ABC news:

<url: http://www.abc.net.au/news/newsitems/200408/s1185358.htm>.

--
A: Because it messes up the order in which people normally read text.
Q: Why is it such a bad thing?
A: Top-posting.
Q: What is the most annoying thing on usenet and in e-mail?
Jul 22 '05 #11

P: n/a
"Steven T. Hatton" wrote:


I have seen a third approach of putting whitespace on either side of the '*'
or '&'. To me this is simply equivocating non-committal.

So I have two questions about this. First which do you prefer and why?
Second, what is the formal grammatical decomposition of a declaration of
the form:

int* i; ?


I very strongly prefer
int* pa;

There are plenty of C++ (not only C) people who have strong preference to
the contrary. See, e.g., the link posted by Gianni Mariani - we didn't
quite get into a flame war, but we were close; you can read there about
our respective reasons, too.

Take a look at
http://www.research.att.com/~bs/bs_faq2.html#whitespace

if you haven't done so already. I couldn't say it better about
"emphasizing type" vs. "emphasizing syntax".

(Note that I do, in a way, emphasize syntax by using the prefix 'p')
A couple more remarks:

I concede that the following is often a source of confusion and
possible errors:

int* pa = 0,
pb = 0;

To me, however, the alternative

int *a = 0,
*b = 0;

is just as bad because "*b = 0;" reads almost exactly as an independent
assignment expression statement (for a previously declared b), which has
a completely different meaning to "int *b=0;".
Of course, you could avoid multiple declarations in the first place.
Nothing is perfect, and C arrays and function pointers are two cases
where the "T*" way doesn't quite fit, but the syntax for these
could (/"should") have been defined differently in C++ from the way
it is in C. I believe there is a discussion about this in DnE, but
I'm sorry if I'm mistaken (I don't have the book handy).

Denis
Jul 22 '05 #12

P: n/a
"Denis Remezov" <fi***************@yahoo.removethis.ca> wrote in message
news:41***************@yahoo.removethis.ca...
"Steven T. Hatton" wrote: <<snip>> is just as bad because "*b = 0;" reads almost exactly as an independent
assignment expression statement (for a previously declared b), which has
a completely different meaning to "int *b=0;".
Of course, you could avoid multiple declarations in the first place.


Looks like a reason to use
int *b=NULL;
for declaration. I'm fond of int* myself, but I use either with no real
hang-up.
--
Gary
Jul 22 '05 #13

P: n/a
Alf P. Steinbach wrote:
* Phlip:
I'm visually impaired - especially when I program while f---ed up - so every little visual cue helps.


Although Australian farmers have found that new technology allows
f--king while farming, see <url: http://tinyurl.com/5btbx>, it's generally


I thought that was New Zealand farmers...
not recommended to f--k while programming, especially not in C++, even if
you have space on both sides and can rely on visual cues.


No no no - I'm talking about getting f---ed up while programming. Other end
of the body.

Good style guides, unit tests, etc. help me remain quite productive, thank
you...

--
Phlip
http://industrialxp.org/community/bi...UserInterfaces
Jul 22 '05 #14

P: n/a
-----BEGIN PGP SIGNED MESSAGE-----
Hash: SHA1

"Steven T. Hatton" <su******@setidava.kushan.aa> wrote in message news:<EN********************@speakeasy.net>...
So I have two questions about this. First which do you prefer and why?


int *ptr. Consider stuff like "int *var1, var2, **var3, var4" or "int
var1, *var2, var3, ***var4". Whether each variable is a pointer or not
(or a pointer to a pointer, or a pointer to a pointer to a pointer...)
is a per-variable thing, not something that applies to the entire line
like int. If you put the asterisk of the first variable with the int,
the rest of the variables just look hokey, whether they are pointers
with their own asterisks next to them or regular ints which now kind
of look like pointers because you stuck the asterisk right with the
int. But of course, this is just my taste, although I think it is a
pretty consistent taste.

Tommy McDaniel
-----BEGIN PGP SIGNATURE-----
Version: GnuPG v1.2.4 (GNU/Linux)

iD8DBQFBLk7ZVB8FYP9YqDcRAt5DAJ9kXZ18V1nKNc6gNuUE6P yG7lwVewCePRGW
LoCe2rR2FmGIFSpn5OlzSbg=
=+h/n
-----END PGP SIGNATURE-----
Jul 22 '05 #15

P: n/a
Howard wrote:
This has been discussed so many times it's ridiculous. But, seeing as I'm
the ultimate "notable authority" (from my perspective, anyway :-)), I
declare that the CORRECT way is to put the * with the type, not with the
variable name. Plus, NEVER declare more than one variable on one line!
(That prevents any chance of confusion, and makes finding the variable
you're looking for much easier.)

However if you declare many variables in the same line, the * with the
variable name is the more reasonable and obvious. Also when you declare
a pointer alone, the * going with the variable name is the more
reasonable too. :-)
How do you dereference by the way * p=7; or *p=7; ?


One other thing I do (which I just know pisses some others off) is to always
precede pointer variable names with the small letter 'p', as in pHead. It's
the only time I use that weird hungarian notation, but it really helps me
recognize pointers from non-pointers. (But that makes me wonder...should a
pointer to a pointer to a Head then be a ppHead? Sorry, bad pun.)

That's naming conventions and it is another thing that we can quibble
on, in the future.


Regards,

Ioannis Vranos

http://www23.brinkster.com/noicys
Jul 22 '05 #16

P: n/a
Denis Remezov wrote:
A couple more remarks:

I concede that the following is often a source of confusion and
possible errors:

int* pa = 0,
pb = 0;

To me, however, the alternative

int *a = 0,
*b = 0;

is just as bad because "*b = 0;" reads almost exactly as an independent
assignment expression statement (for a previously declared b), which has
a completely different meaning to "int *b=0;".
Of course, you could avoid multiple declarations in the first place.

What about
int *pa=0, pb=0;
which is the most elegant and accurate? :-)


Regards,

Ioannis Vranos

http://www23.brinkster.com/noicys
Jul 22 '05 #17

P: n/a
Tommy McDaniel wrote:
int *ptr. Consider stuff like "int *var1, var2, **var3, var4" or "int
var1, *var2, var3, ***var4". Whether each variable is a pointer or not
(or a pointer to a pointer, or a pointer to a pointer to a pointer...)
is a per-variable thing, not something that applies to the entire line
like int. If you put the asterisk of the first variable with the int,
the rest of the variables just look hokey, whether they are pointers
with their own asterisks next to them or regular ints which now kind
of look like pointers because you stuck the asterisk right with the
int. But of course, this is just my taste, although I think it is a
pretty consistent taste.

At last, someone who is reasonable. :-)


Regards,

Ioannis Vranos

http://www23.brinkster.com/noicys
Jul 22 '05 #18

P: n/a
Ioannis Vranos wrote:

Denis Remezov wrote:
A couple more remarks:

I concede that the following is often a source of confusion and
possible errors:

int* pa = 0,
pb = 0;

To me, however, the alternative

int *a = 0,
*b = 0;

is just as bad because "*b = 0;" reads almost exactly as an independent
assignment expression statement (for a previously declared b), which has
a completely different meaning to "int *b=0;".
Of course, you could avoid multiple declarations in the first place.


What about

int *pa=0, pb=0;

which is the most elegant and accurate? :-)


Whichever we happen to like.

Most generally, you cannot declare multiple names of /different/
types in one declaration.

int signed s, unsigned u; //illegal

This is why I see no value (or elegance) in being able to declare
variables of type T and T* (and T**, ...) in one declaration.

Denis
Jul 22 '05 #19

P: n/a
Denis Remezov wrote:
Whichever we happen to like.

Most generally, you cannot declare multiple names of /different/
types in one declaration.

int signed s, unsigned u; //illegal

This is why I see no value (or elegance) in being able to declare
variables of type T and T* (and T**, ...) in one declaration.

You have got the main issue. Since int and int * are different types the
standard should require an error. That's why we are here with this
syntax stuff today.
However based on the fact that they are allowed to be declared together,
and the asterisk denotes a pointer variable, while an object next to it
in the same declaration without an asterisk becomes a non-pointer
object, the most rational thing in this kind of declarations is the
asterisk to go close to the pointer variable itself rather than the type.


Regards,

Ioannis Vranos

http://www23.brinkster.com/noicys
Jul 22 '05 #20

P: n/a
Here my religious answer...............
Typically in my code I write:

int * abc;
char de;
my_type fgh;
int ijkl;
int * mn;
my_long_type opq;
my_type * rstu;
my_long_type * vw;
my_long_type xyz;

My rules (used in the last 20 years):

type variable_name1; /* Only 1 variable per declaration */
type * variable_name2; /* Note the space between type and * */
very_long_type variable_name3; /* All variable-name aligned */
- Dario
Jul 22 '05 #21

P: n/a

"Ioannis Vranos" <iv*@guesswh.at.grad.com> wrote in message
news:cg***********@ulysses.noc.ntua.gr...
Howard wrote:
This has been discussed so many times it's ridiculous. But, seeing as I'm the ultimate "notable authority" (from my perspective, anyway :-)), I
declare that the CORRECT way is to put the * with the type, not with the
variable name. Plus, NEVER declare more than one variable on one line!
(That prevents any chance of confusion, and makes finding the variable
you're looking for much easier.)

However if you declare many variables in the same line, the * with the
variable name is the more reasonable and obvious. Also when you declare
a pointer alone, the * going with the variable name is the more
reasonable too. :-)


That's where I disagree. I think "int* p" declares p to be a pointer-to-int
much better than "int *p", which looks more like a dereferencing of p.

How do you dereference by the way * p=7; or *p=7; ?


I use *p = 7; , but that's the dereference operator being applied, not a
declaration.

-Howard
Jul 22 '05 #22

P: n/a
XZ
>
If you only declare -- and initialise -- variables at the point of first
use, most of these multiple declarations vanish, so the question doesn't
arise ;-).


However, that wouldn't work in C.
Jul 22 '05 #23

P: n/a

"Ioannis Vranos" <iv*@guesswh.at.grad.com> wrote in message
news:cg***********@ulysses.noc.ntua.gr...
Denis Remezov wrote:
Whichever we happen to like.

Most generally, you cannot declare multiple names of /different/
types in one declaration.

int signed s, unsigned u; //illegal

This is why I see no value (or elegance) in being able to declare
variables of type T and T* (and T**, ...) in one declaration.

You have got the main issue. Since int and int * are different types the
standard should require an error. That's why we are here with this
syntax stuff today.
However based on the fact that they are allowed to be declared together,
and the asterisk denotes a pointer variable, while an object next to it
in the same declaration without an asterisk becomes a non-pointer
object, the most rational thing in this kind of declarations is the
asterisk to go close to the pointer variable itself rather than the type.


To me, the rational thing to do is to forbid my staff from declaring
multiple variables on one line in the first place, regardless of their
types. And since I have a staff of one (me), I can enforce that requirement
quite easily! (I rarely disobey myself these days.) :-)

-Howard

Jul 22 '05 #24

P: n/a
XZ wrote:
If you only declare -- and initialise -- variables at the point of first
use, most of these multiple declarations vanish, so the question doesn't
arise ;-).


However, that wouldn't work in C.


As quoted, C has permitted declaration and simultaneous initialization of
variables...

int x = 0;

....since the 1970s.

Were you trying to say something else?

--
Phlip
http://industrialxp.org/community/bi...UserInterfaces
Jul 22 '05 #25

P: n/a
"Dario (drinking co?ee in the o?ce?)" wrote:
Here my religious answer...............
Typically in my code I write:

int * abc;
char de;
my_type fgh;
int ijkl;
int * mn;
my_long_type opq;
my_type * rstu;
my_long_type * vw;
my_long_type xyz;

My rules (used in the last 20 years):

type variable_name1; /* Only 1 variable per declaration */
type * variable_name2; /* Note the space between type and * */
very_long_type variable_name3; /* All variable-name aligned */


Well, that makes sense, because, after all, abc is a data item whose type
is pointer. *abc refers to its contents. So, strictly, int *abc doesn't mean
anything. Or shouldn't. Well, it was that way 20 years ago, please correct
me if I'm wrong - I haven't read the actual Spec yet. Is this Spec available
on the net somewhere, or do I need to piece it together from tutorials and
NG stuff? Buying a book isn't in the budget this week, for the same reason
that all my time is free for learning stuff. ;-)

But this is a C++ group - are pointers really that rampant? I'd have thought
a reference would be more in the spirit of OOps? But I'm a C++ noob, and
learned to cut-n-paste C by guess & by gosh, with K&R at my side. :-)

Thanks,
Rich

Jul 22 '05 #26

P: n/a
Ioannis Vranos wrote:
Denis Remezov wrote:
Whichever we happen to like.

Most generally, you cannot declare multiple names of /different/
types in one declaration.

int signed s, unsigned u; //illegal

This is why I see no value (or elegance) in being able to declare
variables of type T and T* (and T**, ...) in one declaration.

You have got the main issue. Since int and int * are different types the
standard should require an error. That's why we are here with this
syntax stuff today.
However based on the fact that they are allowed to be declared together,
and the asterisk denotes a pointer variable, while an object next to it
in the same declaration without an asterisk becomes a non-pointer
object, the most rational thing in this kind of declarations is the
asterisk to go close to the pointer variable itself rather than the type.

No it's not. The most rational thing is to declare one item, or at most
one type, per declaration, IM!HO.

Cheers!
Rich

Jul 22 '05 #27

P: n/a
Phlip wrote:
XZ wrote:

If you only declare -- and initialise -- variables at the point of first
use, most of these multiple declarations vanish, so the question doesn't
arise ;-).


However, that wouldn't work in C.

As quoted, C has permitted declaration and simultaneous initialization of
variables...

int x = 0;

...since the 1970s.

Were you trying to say something else?

He was probably talking about C90 where variable definitions could occur
only in the beginning of a scope.
However in C99 the can be defined anywhere in a scope, as in C++98.
However I still tend to define all objects in the beginning of scopes
with the exception of for loop counters.


Regards,

Ioannis Vranos

http://www23.brinkster.com/noicys
Jul 22 '05 #28

P: n/a
Rich Grise wrote:
No it's not. The most rational thing is to declare one item, or at most
one type, per declaration, IM!HO.

Why? Do you mean you declare stuff in the style:
int i;
int j;
const int WHATEVER=7;
etc?

Myself use this style:
int i, j, *pName, value;

const int WHATEVER=7;
or
class whatever
{
string firstName, secondName;
// ...
};


Regards,

Ioannis Vranos

http://www23.brinkster.com/noicys
Jul 22 '05 #29

P: n/a
"Ioannis Vranos" <iv*@guesswh.at.grad.com> wrote in message
news:cg**********@ulysses.noc.ntua.gr...
Rich Grise wrote:
No it's not. The most rational thing is to declare one item, or at most
one type, per declaration, IM!HO.


Why? Do you mean you declare stuff in the style:

int i;
int j;
const int WHATEVER=7;
etc?

Myself use this style:
int i, j, *pName, value;

const int WHATEVER=7;


Well, I find that sloppy. I use a mixture as follows:

int i, j, k; // loop stuff and temps
int max; // max value of that thing
int *ptr; // reason I'm pointing at you

So in general, throw-away ints are listed together, but stuff that means
something gets its own line with a comment about what it is for.

Remember, people, we are primarily writers. You are generating script for
the next programmer (who may be you) to understand and act upon. Be generous
in explanation. The compiler won't mind.

--
Mabden
Jul 22 '05 #30

P: n/a
In message <21**************************@posting.google.com >, XZ
<xf*****@hotmail.com> writes

If you only declare -- and initialise -- variables at the point of first
use, most of these multiple declarations vanish, so the question doesn't
arise ;-).


However, that wouldn't work in C.


Have you noticed the name of the newsgroup?

--
Richard Herring
Jul 22 '05 #31

This discussion thread is closed

Replies have been disabled for this discussion.