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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 19, 20262026-05-19T04:59:56+00:00 2026-05-19T04:59:56+00:00

I have a struct with three variables: two unsigned ints and an unsigned char.

  • 0

I have a struct with three variables: two unsigned ints and an unsigned char. From my understanding, a c++ char is always 1 byte regardless of what operating system it is on. The same can’t be said for other datatypes. I am looking for a way to normalize POD’s so that when saved into a binary file, the resulting file is readable on any operating system that the code is compiled for.

I changed my struct to use a 1-byte alignment by adding #pragma as follows:

#pragma pack(push, 1) 
struct test
{
   int a;
}
#pragma pack(pop)

but that doesn’t necessarily mean that int a is exactly 4 bytes on every os, I don’t think? Is there a way to ensure that a file saved from my code will always be readable?

  • 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-19T04:59:56+00:00Added an answer on May 19, 2026 at 4:59 am

    You can find fixed-width integer types (like std::int32_t and std::uint16_t) in <cstdint>. Your C++ Standard Library implementation may not include <cstdint> (it’s not part of the current C++ standard; it’s part of C++0x), in which case Boost has an implementation that should work on most platforms.

    Note that you will still have to think about endianness and alignment, among other things. If your code needs to run on platforms with different numeric representations (e.g. one’s complement and two’s complement), you’ll need to consider that too.

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

Sidebar

Related Questions

I have a struct that contains three lists and an integer as can be
I have a very simple binary tree structure, something like: struct nmbintree_s { unsigned
I have a problem. There are two classes: struct Base { Base* retain() {
I'm running valgrind to look for memory leaks. I have alloc'd two global variables
I have two libraries, from C++ and C, respectively: lib A in C++: typedef
I have a packet from a server which is parsed in an embedded system.
I have a few questions about the linkage from the following variables. By examples
These are two questions about static locals that have always bothered me and I
Suppose I have: struct Magic { Magic(Foo* foo); Magic(Bar* bar); }; Is there a
I'm trying to implement tree algorithms in C. I have declared a extern struct

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.