help-gplusplus
[Top][All Lists]
Advanced

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: std::streampos and INT_MAX - incompatible?


From: Ulrich Eckhardt
Subject: Re: std::streampos and INT_MAX - incompatible?
Date: Fri, 23 Dec 2005 10:27:51 +0100
User-agent: KNode/0.9.2

Al-Burak wrote:
> I have a program that retrieves the cursor position at the point where
> the data began to be stored, this value is assigned to a
> 'std::streampos' data type called 'pos'. Later on in the program, 'pos'
> is put in another file, but as an 'int' data type, as suggested by the
> documentation.

Suggested by what documentation? 

> Having said that, here is my question: If the value of 
> 'pos' exceeds INT_MAX, I will lose the ability to store that data in an
> integral value; 

Right.

> run time error kind of thing (at best!), I suspect. 

Rather truncation and later on wrong position when reading.

> This is most likely to happen since the file size will most definitely
> grow to a size bigger than INT_MAX.
> 
> Can any pitch in a work around?

Store it as a streampos, not as an int. This is not really trivial, because
for one thing the stream position could easily be a 64 bit integer but
there is not necessarily an operator<< and >> for them. The other thing
(but I might be wrong there) is that it also stores an encoding state,
although you might be able to ignore that as long as you only do bytewise
reading with the classic locale.

Uli

-- 
http://gcc.gnu.org/faq.html
http://parashift.com/c++-faq-lite/



reply via email to

[Prev in Thread] Current Thread [Next in Thread]