atof() returns a double, which results in a warning when I assign it to a float-value (and yes, I definitively have to use float).
So my question: is there a
atof()-variant available which returns a plain float? Or do I have to solve this by a cast - which would be a pity because it wastes resources for creating a double which will be thrown away immediately.
strtof instead, it will return a float.
See documentation here
If the platform does have a direct "string to float" conversion routine and the compiler is optimizing, it will certainly call that conversion routine via:
char *buf = ... float y; if (sscanf(buf, "%f", &y) == 1) Success();
If not, then use
float y = (float)atof(buf);
Note that the second could be optimized by the compiler to call the "string to float" if it violates the subtle double rounding that otherwise occurs with this 2nd code.