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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 23, 20262026-05-23T18:15:34+00:00 2026-05-23T18:15:34+00:00

I was wondering if there is a GCC C Compiler directive that allows me

  • 0

I was wondering if there is a GCC C Compiler directive that allows me to determine the bit order for packing of a structure? Something to the likes of:

#pragma bit_order left

The rationale for such a need is that I have the following structure:

struct {
       union {
             unsigned char BYTE;
             struct {
                 unsigned char B0: 1;
                 unsigned char B1: 1;
                 unsigned char B2: 1;
                 unsigned char B3: 1;
                 unsigned char B4: 4;
             }BIT;
       }ITEM;
} myStruct;

With this structure, I would like the compiler to pack it this way:

Bit order: | 7  6  5  4  3  2  1  0 |
Label:     |B0 B1 B2 B3 B4 B5 B6 B7 |

Rather than how GCC does it:

Bit order: | 7  6  5  4  3  2  1  0 |
Label:     |B7 B6 B5 B4 B3 B2 B1 B0 |

I am dealing with MCUs that have huge header files that have structures that compute bit offsets according to stipulated hardware addresses. I am hoping that there is a compiler directive in GCC C Compiler that does the bit order swap for me before I attempt the flip all the fields in the manufacturer supplied file.

  • 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-23T18:15:35+00:00Added an answer on May 23, 2026 at 6:15 pm

    Which version of GCC are you using and which platform? A pragma exists that may do the trick, but it doesn’t work on x86 starting with GCC 4.

    #pragma reverse_bitfields on
    

    More details at:

    http://groups.google.com/group/gnu.gcc.help/browse_thread/thread/747918655affa5c0?pli=1

    If you don’t mind rebuilding GCC, all the relevant build settings are here (search for bitfield):

    http://gcc.gnu.org/onlinedocs/gccint/Storage-Layout.html

    Some details about bitfields being bad:

    C/C++: Force Bit Field Order and Alignment

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

Sidebar

Related Questions

I was wondering if there is some compiler parameter, preferably in gcc (g++) which
gcc 4.4.4 c89 I am just wondering is there any standard that should be
Wondering if there is any way to get the lambda expressions that result from
Wondering if there is a good way to generate temporary URLs that expire in
was wondering if there are anyone else here that has signed up with the
I was wondering if there exists an application for mobile phones(any platform) that simulates
linux gcc 4.4.1 C99 I am just wondering is there any advantage using the
I was wondering is there a free Windows version of GCC. I know there
I'm wondering if there is a nice way to avoid gcc to scream about
Wondering if there is any Text to Speech software available as a plug in

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.