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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 3, 20262026-06-03T03:00:57+00:00 2026-06-03T03:00:57+00:00

Is there a portable equivalent of __attribute__ ((__packed__)) (by portability I mean working on

  • 0

Is there a portable equivalent of __attribute__ ((__packed__))

(by portability I mean working on PC, Android and iPhones, regardless architecture)

  • 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-03T03:00:58+00:00Added an answer on June 3, 2026 at 3:00 am

    By definition, __attribute__s are non-portable. If you want your data a specific way, the Plan9 solution is usually to use unsigned char arrays in your structure:

    struct foo {
        uchar data1[4];
        uchar other[2];
    }
    

    Usually won’t have any alignment, since it’s fundamentally using unsigned characters. Of course, if you have a high tolerance for pain, you could always use an enum of offsets:

    enum { FOO_DATA1=0, FOO_OTHER=4, FOO_LAST=6 };
    

    You could then load it up like so:

    unsigned char foo[FOO_LAST];
    uint32_t n = htonl(val)
    memcpy(foo+FOO_DATA1, &n, sizeof n)
    memcpy(foo+FOO_OTHER, &some_16_bit_val, sizeof some_16_bit_val)
    

    As long as you have the stomach for it, it will be completely portable.

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

Sidebar

Related Questions

s there Portable Class Library equivalent to MethodBase.GetCurrentMethod? I'm new to PCLs. I'm justing
Is there a (portable) way to rotate text in a HTML table cell by
Is there a portable way to convert a UTF-8 string in C to upper
Is there a portable way to run a python script from a shell without
Is there a well-known, portable, good library for C++ process management? I found a
During this year there will be coming couple sub-600€ multi-touch portable computers that contain
Is there any portable version of Visual Studio (2005, 2008, 2010..)? Is it possible
Is there a portable C library to access .zip archives? gzip or zlib (the
Is there any portable (Windows & Linux) way of counting how many milliseconds elapsed
Is there a portable way, that works on both .Net and Mono on 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.