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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 20, 20262026-05-20T10:11:23+00:00 2026-05-20T10:11:23+00:00

I will use this code as an example: typedef struct __attribute__((aligned(XXX),packed)) { uint16_t type;

  • 0

I will use this code as an example:

typedef struct __attribute__((aligned(XXX),packed))
{
   uint16_t type;
   uint32_t id_index;
} a_msg;

void write_func(){
   a_mesg mymsg
   mymsg.type = htons(1);
   mymsg.id_index = htonl(5);
   write(sock_fd, &mymsg, sizeof(a_mesg));
}

void read_func(){
   a_mesg mymsg
   read(sock_fd, &mymsg, sizeof(a_mesg));
   mymsg.type = ntohs(mymsg.type);
   mymsg.id_index = ntohl(mymsg.id_index);     
}

Note: sock_fd is a tcp socket. This is a bit compressed example and would maybe not work but I think you see what I am trying to exemplify (a program that communicates over a binary protocol).

If the application would only run on two 32 bit machines, that communicate with each other through the application, the alignment (aligned(XXX)) would naturally be set to 4. If we communicate in between a 32 bit machine and a 64 bit machine what would the alignment be?

  1. Should XXX be 4 on both 32 and 64 bit machines?
  2. Should XXX be 8 on both 32 and 64 bit machines?
  3. Should XXX be 8 on 64 machines and 4 on 32 bit machines?
  4. XXX is of some other value.

My bet is on alternative 2.

  • 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-20T10:11:24+00:00Added an answer on May 20, 2026 at 10:11 am

    I am doing

    __attribute__((aligned(1),packed))
    

    it works =)

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

Sidebar

Related Questions

We use Spring + Hibernate for a Webapp. This Webapp will be deployed on
I'd like to use visitor IP addresses into a company name. This will be
I have an application thats going to use Active Directory for Authentication. This will
I want to use a temp directory that will be unique to this build.
I use this code to retrieve JSON details from php call and I add
Many times I will use the same font scheme for static text in a
I am writing my first project that will use autoconf and teaching it to
I am building a simple Django app that will use scribd to display documents.
I want to execute a php-script from php that will use different constants and
We are currently working on an application that will use a WCF service. The

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.