Not.
If the character array does not end with a null character, then this is not a string. If any of the strto*()
functions is passed an argument that does not point to a string, the behavior is undefined.
Recalling the latest draft of the ISO C 2011 standard:
7.1.1 Definition of terms:
A string is a continuous sequence of characters terminated by and including the first null character.
7.1.4 Using library functions:
If the function argument has an invalid value (for example, a value outside the function area or a pointer outside the address, program space or a null pointer or a pointer to unmodifiable storage when the corresponding parameter is not const-qualified) or type (after promotion), not expected function with by a variable number of arguments, the behavior is undefined.
7.22.1.3 Functions strtod, strtof and strtold:
The strtod , strtof, and strtold functions convert the start of the string pointed to by nptr to double , float, and a long double representation.
(in italics)
Thus, an argument that does not point to a string is outside the domain of the function.
You probably will not succeed if the array contains something like { '1', '2', '3', 'x', 'y', 'z' }
, since it does not need to scan the passage of x
, which completes the required value, but the behavior is clearly undefined.
If you want to use these functions, you must, if necessary, copy your array to another buffer and explicitly disable it yourself.