On Oct 8, 11:29 am, p...@informatimago.com (Pascal J. Bourguignon)
wrote:
> Maxim Yegorushkin <maxim.yegorush...@gmail.com> writes:
> > On Oct 8, 3:36 pm, Juha Nieminen <nos...@thanks.invalid> wrote:
> >> REH wrote:
> >> > It it permissible to use the constructor style cast with primitives
> >> > such as "unsigned long"? One of my compilers accepts this syntax, the
> >> > other does not. The failing one chokes on the fact that the type is
> >> > not a single identifier or keyword. Which one is correct? For example:
>
> >> > unsigned long x = unsigned long(y);
>
> >> If I'm not mistaken, if you want to make a C-style cast to a type
> >> which consists of several keywords, you have to enclose them in
> >> parentheses. That is:
>
> >> unsigned long x = (unsigned long)(y);
>
> >> Of course the recommended way in C++ is to use a C++ style cast:
>
> >> unsigned long x = static_cast<unsigned long>(y);
>
> > The original question, IMO, involved C++ functional style cast, rather
> > than C-style cast.
>
> Which funnily, is not decided when you write:
>
> unsigned long x = (unsigned long)(y);
>
> The compiler could as well decide to parse it as a C cast as a C++
> functional style cast. I think it'll be my favorite way to write it,
> let the compiler deal with it as it wants :-)
>
Maxim understands that it was a question about syntax, not semantics.
REH