Obviously it can only be a double because that's what the compiler casts it to. I was making a point about clarity (really a style comment), not about correctness. The code
return 0;
can be used for ints, floats, doubles, longs, shorts, pointers, unsigned and signed, etc. Providing a constant of the proper type is a way of telling code reviewers "yes, I meant to return a double with value 0.0".
If you know you are returning a double, writing
return 0.0;
provides a constant of the type being returned, and the compiler does not have to cast the value to another type before returning it. At our company, a code inspection comment like this would be perfectly appropriate, and the change would most likely be made to enhance readability and maintainability.
By the way, does the following code look OK to you? It has the same clarity issues, just in reverse.
1 2 3 4
|
int myFunction
{
return 0.0;
}
|