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

  • Home
  • SEARCH
  • 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 8495275
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 10, 20262026-06-10T23:31:44+00:00 2026-06-10T23:31:44+00:00

If i have a structure like struct MixedStructure{ char a; short b; int c;

  • 0

If i have a structure like

struct MixedStructure{
char a;
short b;
int c;
char d;
};

Padding will come to effect.

What I want to know, is if there is a problem sending such a structure over the network.

I mean, this structure actually has 12 bytes (instead of 8) because of padding. If at the other end there is used another padding scheme ( or none), what would be the implications ?

  • 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-10T23:31:45+00:00Added an answer on June 10, 2026 at 11:31 pm

    That’s not your only problem. How do you know the sizeof(int) or sizeof(short) is going to be consistent between the two boxs that build that struct?

    Most compilers have ways to specify fixed-size variables (ie uint32_t). To answer your specific question, most compilers also have ways to specify packing.

    Overlaying a struct onto a buffer of bytes is a very common idiom in high-performance network programming but can be frought with peril. You’ll also need to learn about how this idiom violates strict-aliasing and what endianess is.

    I know that in very high-performance situations this is the best option. Just be very very careful and test very well between all the potential hosts that might communicate together. If you don’t need this kind of performance, check out something like google’s protocol buffers for transmitting data in a pretty performant way that lets you avoid knowing about packing/endianess/etc.

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

Sidebar

Related Questions

I have a structure like struct board{ char name; int values[37]; }board Imagine a
Let's say I have a first structure like this: typedef struct { int ivalue;
I have structure like this below. Now, I want swap 2 structures. public struct
I have a structure defined like so: typedef struct { int n; int *n_p;
I have a List of an Record(structure) like this : struct Rec { int
If I have structure definitions, for example, like these: struct Base { int foo;
I have a structure like struct category { int id,newID; std::string name; }; and
I have a data structure like this: struct foo { int id; int route;
I have a structure like this. struct A { int someFun() const; int _value;
I have program, that has structure defined like this: struct foo { int magic;

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.