[Development] The age-old T* foo vs. T *foo

Ville Voutilainen ville.voutilainen at gmail.com
Thu Oct 17 22:00:55 CEST 2019

On Thu, 17 Oct 2019 at 22:34, Jason H <jhihn at gmx.com> wrote:
> You're staring down the business end of a Saturn-V...
> I for one, never liked
> QObject* x, y;
> because x is a pointer, and y is not. It seems like they should both be QObject*s.
> Meanwhile:
> QObject *x, y;
> makes it very clear (clearer?) that x is a pointer and y is not.
> Parenthesizing things shows just how awkward it is:
> QObject(* x), (y); // really gotta reach for that star. (See what I did there!?)
> vs.
> QObject (*x), (y);
> Of course readability was never C's strong suit.
> I'd be ok with single decleartions:
> QObject* x; // can't miss interpret this
> QObject y;  // or this
> But because you can have multiple variable declarations on a line (arguably the real thing to change) we're stuck with the confluence of two rules yielding chaos. This is an unfortunate lack of specificity in the standard.

I don't think this is news to anyone, but the usual suggestion to
avoid that problem is not writing comma-separated declarations. That
tends to work perhaps surprisingly well, in practice.

More information about the Development mailing list