Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 6690689
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 26, 20262026-05-26T05:39:58+00:00 2026-05-26T05:39:58+00:00

I am creating my own streambuf subclass and using the C++03 spec (ISO/IEC 14882:2003)

  • 0

I am creating my own streambuf subclass and using the C++03 spec (ISO/IEC 14882:2003) as a reference.

In section 27.5.2.4.2 [lib.streambuf.virt.buffer], the specifications for both basic_streambuf::seekoff() and basic_streambuf::seekpos() say:

Default behavior: Returns pos_type(off_type(-1)).

Now, I thought off_type was supposed to be a signed integral type and pos_type was supposed to be an unsigned integral type, so it seems to me this expression has to be equivalent to just pos_type(-1).

But supposing I am mistaken, and these types might be some other combination of signed and unsigned… Then I still cannot figure out any possible use for this double cast.

For example, if both are signed, then again the expression is equivalent to pos_type(-1).

If pos_type were signed and off_type were unsigned — which makes no sense, but bear with me — then at best this double cast would shove some huge value into pos_type and at worst it would invoke implementation-defined behavior by assigning a too-large value to the signed pos_type integer.

Does anyone know the standard’s rationale for specifying pos_type(off_type(-1)) here instead of just pos_type(-1)? If not, can you even imagine a plausible rationale?

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-26T05:39:59+00:00Added an answer on May 26, 2026 at 5:39 am

    I believe that pos_type by default boils down to a std::streampos, which is typically defined like this:

    typedef fpos<mbstate_t> streampos;

    std::fpos is usually an offset combined with a multi-byte state object.

    Additionally, off_type by default will boil down to a std::streamoff which is also a signed integral type (long or something like that)

    So I think the mentality here is that you can initialize a offset type with the sentinal -1 value, then that can be used to initialize a position object which is a more complex object. Because, fpos‘s constructor takes streamoff type, not a long, if streamoff could be a more complex type than a long or similar, it would make the cautious-ness necessary.

    Imagine an implementation where streamoff was defined like this:

    struct streamoff {
        explicit streamoff(long offset);
        // rest of the stuff here...
    };
    

    Then just pos_type(-1) wouldn’t work because there would be no implicit conversion.

    So I think it’s just being cautious.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I am using media player to play audio and video. I am creating own
I am considering creating my own website using Java and am trying to decide
I'm just creating my own AboutBox and I'm calling it using Window.ShowDialog() How do
When creating own Activity subclass, we are overriding some of the basic Activity lifecycle
I'm creating my own recipe box using php/mysql and one part I'm stuck on
i am having difficulties creating my own Zend_Auth_Adapter. i am using Doctrine 2 with
I am currently creating my own custom section headers but I have never dont
I'm creating my own HashSet that works as the standard HashSet, using a Dictionary.
I'm creating my own 2D engine. I planned on just using the .net drawing
I'm creating my own template engine using PHP. The basic idea is that for

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.