December 23, 2001
Walter wrote:

> "Robert W. Cunningham" <rwc_2001@yahoo.com> wrote in message news:3C24E40C.7FEF7E02@yahoo.com...
> > I know it has been long, long ago in a thread far, far away, but I still like the "functional" form of casting:
> >
> > int i = 30;
> > float j = float(i);
>
> The trouble with the functional form is, suppose you want to cast to foo*:
>
>     foo*(i)
>
> It doesn't work in the general case, so an alternate form must be there anyway.

Personally, my style would be to create a typedef, then cast using that.  Of course, that could become cumbersome, when lots of pointers to lots of types are used, but then again, perhaps a little hassle is a good thing in such situations.  IMHO, the real problem is the syntax related to "*":  That's what needs fixing in a way that will allow casting to be clarified and de-uglified.  (Of course, the language idealists would eliminate the problem simply by outlawing casting.  So they'd say all solutions to the casting problem would, by definition, be ugly.  They'd probably get rid of pointers too.)

We should be able to shove the asterisk inside the parens without loss of clarity:

  foo(*i);

Then this small voice in my head said:  "OK smarty-pants, what about casting foo to be a pointer to a function that returns a pointer to a function returning an array of ints?"

This is a situation where placing one's fingers in one's ears only makes the small voice louder.

Time for bed.


-BobC


1 2
Next ›   Last »