TransWikia.com

Do I really have to cast float to uint8_t if I just want to convert 203.0 to 203 at a microcontroller?

Electrical Engineering Asked on November 23, 2021

In computers, it’s OK to use float as an argument where the argument should actually be a uint8_t

void myFunction(uint8_t myVal);

But what if I call this function myFunction(value); where value is of datatype float inside a microcontroller? The microcontroller have single precision included. The variable value have its range from 0 to 250 in this case.

Do I need to call my function myFunction((uint8_t) value) ?

One Answer

No need to do explicit cast, the compiler knows what to do implicitly, just like when you assign the float to an integer variable for example.

Answered by Justme on November 23, 2021

Add your own answers!

Ask a Question

Get help from others!

© 2024 TransWikia.com. All rights reserved. Sites we Love: PCI Database, UKBizDB, Menu Kuliner, Sharing RPP