D
dpbsmith.janissary.2006
I know C++ mostly from "learning by doing." My main reference is
Stoustrup's book. I was puzzled by something in a colleague's code that
looked like this:
abc=BOOL(def)
I asked him what that was, and he said "it's a cast." I know all about
dynamic_cast and friends, but this was something new to me. To make a
long story short, both of my colleagues seemed to be familiar with
writing a cast as if it were a function, although they don't normally
write them that way, and Stoustrup's book has actual instances of this
that appear in some of his code examples. A colleague was able to find
something in the formal C++ syntax description indicating it's valid...
but nobody was able to point me to any documentation, description, or
explanation.
If this is described in Stroustrup's book, I couldn't find it. I
thought "deprecated C-style cast" might be it, but, no, that's just the
regular C cast syntax, and I've verified that C compilers do _not_
accept writing a cast as if it were a function.
It is not a Microsoft-ism, either, which was my other thought; other
C++ compilers seem to accept it.
So, what the heck is it? Is it fully legitimate C++? Does it have any
differences whatsoever from a "normal" cast, i.e. do
hij = long(klm);
and
hij = (long) klm;
compile identical code? If so, what is it there for? Is it just an
unintended consequence of things that needed to be done to extend C
syntax to C++? And where exactly in Stoustrup's book is it described
and explained?
Stoustrup's book. I was puzzled by something in a colleague's code that
looked like this:
abc=BOOL(def)
I asked him what that was, and he said "it's a cast." I know all about
dynamic_cast and friends, but this was something new to me. To make a
long story short, both of my colleagues seemed to be familiar with
writing a cast as if it were a function, although they don't normally
write them that way, and Stoustrup's book has actual instances of this
that appear in some of his code examples. A colleague was able to find
something in the formal C++ syntax description indicating it's valid...
but nobody was able to point me to any documentation, description, or
explanation.
If this is described in Stroustrup's book, I couldn't find it. I
thought "deprecated C-style cast" might be it, but, no, that's just the
regular C cast syntax, and I've verified that C compilers do _not_
accept writing a cast as if it were a function.
It is not a Microsoft-ism, either, which was my other thought; other
C++ compilers seem to accept it.
So, what the heck is it? Is it fully legitimate C++? Does it have any
differences whatsoever from a "normal" cast, i.e. do
hij = long(klm);
and
hij = (long) klm;
compile identical code? If so, what is it there for? Is it just an
unintended consequence of things that needed to be done to extend C
syntax to C++? And where exactly in Stoustrup's book is it described
and explained?