Boost logo

Boost :

From: Bronek Kozicki (brok_at_[hidden])
Date: 2005-10-29 12:26:43


Oliver Kullmann wrote:
> Sure, for the language lawyers. But my point here is to argue that
> it is NOT POSSIBLE to read integers in C++ from an input stream without
> running into undefined behaviour (if we do not have perfect control over
> the size of numbers), and w.r.t. this the C90 standard is just worse than
> the C99 standard.
>
>>It simply leaves
>>this question not-standarized and the C++ standard does not add anything
>>in this respect.
>
> The only difference between "not-standardized" and "undefined behaviour" is, that
> in the latter case we are at least conscious about it, while in the former case
> we have no clue (and closing the eyes before a problem doesn't usually solve the
> problem).

No at all. If you were right, then we would have been unable to write
multithreaded programs, programs that use dynamic libraries etc. -
because these isues are left out of standard (C++ and C). The fact is
that when something is left out of standard, it is actually left to
implementor. The very issue you are rising here has been actually
discussed by the C++ standard committee and conclusion was that
currently there is no risk of UB. There are worse problems to solve, eg:

int main()
{
   int a, b;
   std::cin >> a >> b;
   int c = a * b; // potential UB here
}

B.


Boost list run by bdawes at acm.org, gregod at cs.rpi.edu, cpdaniel at pacbell.net, john at johnmaddock.co.uk