By using this site, you agree to our updated Privacy Policy and our Terms of Use. Manage your Cookies Settings.
446,413 Members | 999 Online
Bytes IT Community
+ Ask a Question
Need help? Post your question and get tips & solutions from a community of 446,413 IT Pros & Developers. It's quick & easy.

std::streampos and INT_MAX - incompatible?

P: n/a
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. 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; run time error kind of thing (at best!), I suspect.
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 on a work around?
Thanks in advance.

Dec 22 '05 #1
Share this Question
Share on Google+
2 Replies


P: n/a

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. 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; run time error kind of thing (at best!), I suspect.


On the risk of sounding obvious: why not store std::streampos values
in std::streampos objects? That won't overflow.

HTH,
Michiel Salters

Dec 22 '05 #2

P: n/a
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. 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; run time error kind of thing (at best!), I suspect.
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 on a work around?
Thanks in advance.


My implementation bears this comment in postypes.h:

// The types streamoff, streampos and wstreampos and the class
// template fpos<> are described in clauses 21.1.2, 21.1.3, 27.1.2,
// 27.2, 27.4.1, 27.4.3 and D.6. Despite all this verbage, the
// behaviour of these types is mostly implementation defined or
// unspecified. The behaviour in this implementation is as noted
// below.

So, you either need to convert the streampos to an integral type that
is large enough for your needs, or you need to supply an operator to
stream your implementation's version of streampos. In either case, it
will likely be implementation-dependent.

Cheers! --M

Dec 22 '05 #3

This discussion thread is closed

Replies have been disabled for this discussion.