if (sscanf(string,"%lf",&foo) != 1)
{
bad_float();
}
This has the benefit of handling scientific notation, too, which some of the other CRTL functions inexplicably do not.For extra reassurance, initialize foo to NaN or DBL_MAX or something, and verify that it is no longer equal to that value.
sscanf has locale things that make it include implementation-defined behaviour, doesn't it?
That doesn't detect overflows and underflows. Also changes based on locale, which is not thread safe (so you cannot set locale, convert, then unset locale).