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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 23, 20262026-05-23T20:35:44+00:00 2026-05-23T20:35:44+00:00

If I store a float in a file via this code fwrite((void*)(&v), sizeof(v), 1,

  • 0

If I store a float in a file via this code

fwrite((void*)(&v), sizeof(v), 1, f); // v is a float.

how often will a program reading the file with this code cause a runtime error because float is 8 bytes instead of 4?

float v;
fread((void*)(&v), sizeof(v), 1, f);
return v;

Can I always read 4 bytes and cast that to an 8 byte float? Would that be more portable?

Emphasis on different Windows Platforms 64 bit vs 32 bit.

  • 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-23T20:35:44+00:00Added an answer on May 23, 2026 at 8:35 pm

    I would be less worried about the size of the float and more worried about the endianness of it. I’d say the vast majority of C++ implementation use IEEE 754 which would mean float is always going to be 32 bits and double 64 bits.

    You may wish to just serialize a text representation of the value, or else take particular care to make sure that the byte order is correct.

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

Sidebar

Related Questions

I have an application which will store a series of (float) values in an
I am creating a utility that will store data on flat file in a
Should I use decimal or float to store a ratio in a database? Particularly
I have a problem. My proget create a xml file. In the iPhone this
First I will give a little background info so this question isn't completely without
I've got some code to convert a large (many gigabytes) XML file into another
In some C++ code, I use integers to store lots of changing data. To
I have this method to get xml file from google reader with the contens
Often, when I need to store system properties like admin info, versions, and so
I'm looking for a flat-file, portable key-value store in Python. I'll be using strings

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.