[cctbxbb] Idiot C++ question

David Lonie loniedavid at gmail.com
Tue May 15 03:35:40 PDT 2012


Hi Phil,

A lot of people have this question, and it does seem unnecessary when
a C-style cast (e.g. double d = double(i);) is easier. The FAQ at
http://www2.research.att.com/~bs/bs_faq2.html#static-cast gives some
of the reasons. The main two are: C style casts are vague -- there are
a few logically different types of casting, and the C style cast
doesn't really provide the compiler with enough information about what
sort of cast is to be performed. The other reason that I hear a lot
is, to quote the FAQ: "An ugly operation should have an ugly syntactic
form." C style casts are next to impossible to search for, and they
blend in when visually inspecting code. The C++ casting methods stick
out like sore thumbs, as they should ;-)

Hope this helps,

Dave

On Tue, May 15, 2012 at 4:17 AM, Phil Evans <pre at mrc-lmb.cam.ac.uk> wrote:
>
> Looking at some cctbx C++ code, I note use of syntax like
>
> int i = 1234;
> double d = static_cast<double>(i);
>
> How is this different or indeed preferable to
>
> double d = double(i);
>
> or
>
> d = i;
>
> ?
>
> Phil
> _______________________________________________
> cctbxbb mailing list
> cctbxbb at phenix-online.org
> http://phenix-online.org/mailman/listinfo/cctbxbb


More information about the cctbxbb mailing list