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 8640189
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 12, 20262026-06-12T11:13:10+00:00 2026-06-12T11:13:10+00:00

To measure position/offsets/size of streams, the standard specify std::streampos , std::streamoff and std::streamsize ,

  • 0

To measure position/offsets/size of streams, the standard specify std::streampos, std::streamoff and std::streamsize, but they are implementation defined.

How to convert these types to long long int in a secure and portable way ? (for example to measure a file size and inject it in a function that take a long long int as argument)

  • 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-06-12T11:13:11+00:00Added an answer on June 12, 2026 at 11:13 am

    Well, as far as C++98/03 is concerned, there is no long long int. So I’ll assume you’re asking about C++11.

    The streamsize and streamoff are required to be typedefs of an integral type (streampos is not an integer, so you won’t be passing that to anything that takes a long long). Since integral types are basic types, they can only be defined by either C++ or as a compiler-specific definition.

    Thus, the only question is this: are these typedefs larger than long long? All integral types are convertible to a larger or equal-sized type (signed/unsigned notwithstanding, but all of the types here are signed, so no problem). But if it is larger… what are you going to do about it?

    Assuming you can’t change the signature of the function you are “injecting” it into (because if you could, there’s no reason not to just take streamsize as the parameter type and thus avoid the problem), you don’t have any options. You have a data value that is larger than what the function takes. There’s no way of getting around it here.

    You can perform a static_cast into a long long to shut the compiler up, but this won’t help if the actual size can’t fit in a long long.

    Ultimately, this is an intractable problem. You have a function that takes a parameter which is potentially too small for what you’re passing. The most you can do is detect when it might be a problem via a static_assert. Something like this:

    static_assert(sizeof(std::streamsize) <= sizeof(long long), "Oops.");
    

    To be honest, I wouldn’t worry about it. Odds are good that long long will be the largest integral size that your compiler natively supports.

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

Sidebar

Related Questions

I'm trying to measure the popularity of a post but there's no current system
2D problem: I measure the position of the 3 ends of a triangle in
I'm using positioning.position(). but this function is blocking. I want to be able to
It seems to me that both depth and position.z measure the distance between the
I need to store my app window's size/position and state when the user closes
In Java, how can I measure the speed of the mouse movement but disable
We use interceptors to measure the execution time of a bean's public method invocation.
In some measure of progress since my last question I have got the following
I need measure how time took a scriptblock (remote execution). This is my code:
I have a measure, that's a distinct count on a field in the fact

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.