Is it OK to use C-style cast for built-in types?

后端 未结 9 853
情书的邮戳
情书的邮戳 2020-12-01 16:09

After reading here a lot of answers about C-style casting in C++ I still have one little question. Can I use C-style casting for built-in types like long x=(long)y;

9条回答
  •  臣服心动
    2020-12-01 17:00

    I think it may be OK given the context. Example:

    /* Convert -1..1 to -32768..32767 */
    short float_to_short(float f)
    {
        return (short)(max(-32768.f, min(32767.f, f * 32767.f)));
    }
    

提交回复
热议问题