Need some clarification regarding casting in C

后端 未结 13 2103
野趣味
野趣味 2020-12-20 04:01

I was just reading about the bad practice of casting the return value of malloc. If I understood correctly, it is absolutely legal to leave the cast as it is do

相关标签:
13条回答
  • 2020-12-20 04:57

    What you're looking at is implicit type conversion. This is considered safe if you're starting with a type having a more restricted range than the one you're ending up with, i.e. short to int is OK, as is float to double.

    I'm quite surprised that gcc isn't generating a warning when converting a double to a float; I believe Microsoft's compiler does.

    0 讨论(0)
提交回复
热议问题