473,405 Members | 2,334 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,405 software developers and data experts.

std::streampos and INT_MAX - incompatible?

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
2 3959

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
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 thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

5
by: Asfand Yar Qazi | last post by:
Hi, Just wondering, if I do a: std::set_new_handler(std::terminate) I won't have to worry about a std::bad_alloc being thrown when I do a 'new ...' or a 'new(nothrow) ...', right? Its...
7
by: zbyszek | last post by:
I am working with a large C++ program which, for reasons of backward compatibility, uses C's printf and fprintf rather than iostreams. For a certain type of build I want to provide new functions...
7
by: vikky | last post by:
hi all, Out of sheer curosity, I decided to initialize an integer with a number bigger than INT_MAX, however I still am not able to justify its output. Here is the program : #include<stdio.h> ...
1
by: Al-Burak | last post by:
After storing the cursor possition in a file, I try to read it back, std::ofstream >> std::streampos, but this statement gives me an error syaing: file.cpp: In member function `virtual...
6
by: Shiraz | last post by:
Me and my colleagues have been working on a problem since yesterday and can’t seem to find a solution to it. It relates in a good measure to iterators and the way we’re using them in our...
84
by: Peter Olcott | last post by:
Is there anyway of doing this besides making my own string from scratch? union AnyType { std::string String; double Number; };
13
by: william | last post by:
code segment: long int * size; char entry; ............. size=&entry; ************************************* Gcc reported 'assignment of incompatible pointer type'.
24
by: Yevgen Muntyan | last post by:
Hey, Is it correct that number of value bits in int and unsigned int representation may be the same? If it is so, then INT_MIN may be -(INT_MAX+1) (in mathematical sense), i.e. abs(INT_MIN) is...
27
by: mike3 | last post by:
Hi. I can't believe I may have to use an array here. I've got this bignum package I was making in C++ for a fractal generator, and tried an approach that was suggested to me here a while...
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
0
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
0
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
0
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...
0
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...
0
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing,...
0
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome a new...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.