[Qt-interest] I am facing a problem

Oliver.Knoll at comit.ch Oliver.Knoll at comit.ch
Wed Aug 12 17:37:24 CEST 2009


Sujan Dasmahapatra wrote on Wednesday, August 12, 2009 5:23 PM:

> I am reading an int and a double from file. 

Ah, so this a *totally different issue* than the one you had before! Please start new threads when asking *new* questions.

> Can u tell me how could I
> check whether it's an int or double. 

So you are reading a bunch of bytes of "unknown nature". How - in your own words and imagination - should *any* function know whether the data you read as int or double should be really an int or double? In other words:

- you write an int, you read it as double -> "random value" (or an EOF exception, depending on whether there is more data after the "int")
- you write a double, you read an int -> "random value"

If you are lucky you get  MAX_INT, NaN, or whatever (see std::numeric_limits<>::infinity|quiet_NaN|signaling_NaN(). But whether a bunch of bytes is supposed to represent an int or double is impossible without further knowledge about the file structure! 

Unless you prove me wrong. 


Cheers, Oliver
-- 
Oliver Knoll
Dipl. Informatik-Ing. ETH
COMIT AG - ++41 79 520 95 22



More information about the Qt-interest-old mailing list