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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 26, 20262026-05-26T11:35:31+00:00 2026-05-26T11:35:31+00:00

I am converting a vxWorks application to Linux. Previously, I had a union with

  • 0

I am converting a vxWorks application to Linux.

Previously, I had a union with a word and a struct so that when I accessed the members of the struct, I could use the word's layout to build my struct members.

However, I don’t recall how I figured this out and it works on the vxWorks box. On my vxWorks instance, the layout is:

typedef union Status
{
    struct fields
    {
        uint32_t byteA : 1; // <31>
        uint32_t blank : 23; // <30:8>
        uint32_t bytesN : 8; // <7:0>
    } fields;

    uint32_t word;
}

I’ve already ran into some endian issues while porting from vxWorks to Linux. So figuring out the layout of uint32_t on linux is important.

  • 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-26T11:35:32+00:00Added an answer on May 26, 2026 at 11:35 am

    From your comment to the other answer, you want whatever is stuffed into the word member of the union to appear in the fields.bytesN member. To achieve this you must either have some kind of pre-build process that lays out the field bit fields appropriately after detecting machine endianness, or create 2 structures, one for big endian and the other for little endian.

    typedef union Status
    {
        struct fieldsBE
        {
            uint32_t byteA : 1; // <31>
            uint32_t blank : 23; // <30:8>
            uint32_t bytesN : 8; // <7:0>
        } fieldsBE;
    
        struct fieldsLE
        {
            uint32_t bytesN : 8; // <7:0>
            uint32_t blank : 23; // <30:8>
            uint32_t byteA : 1; // <31>
        } fieldsLE;
    
        uint32_t word;
    };
    
    int main()
    {
      bool isBigEndian = DetectEndianness(); // returns true if big endian
    
      Status status;
    
      status.word = 40;
    
      if( isBigEndian ) {
        uint8_t bytesN = status.fieldsBE.bytesN;
    
      } else {
        uint8_t bytesN = status.fieldsLE.bytesN;
    
      }
    }
    

    Of course, if you only want to support little endian in your port use the layout of fieldsLE instead of the original layout you’ve shown.

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

Sidebar

Related Questions

I'm converting an application to use Java 1.5 and have found the following method:
I am considering converting a project that I've inherited from .net 1.1 to .net
I'm converting an old app that records folder sizes on a daily basis. The
While converting a project that used SlimDX, and therefore has unmanaged code, to .NET
Converting an existing Android application to a library is incredibly simple : All I
IN converting over a legacy application we need to convert named query to nhibernate.
While converting a Java application to C# I came through a strange and very
I´m converting a Linux Logger to work in windows. The logger prints with snprintf.
I'm converting existing database driven application from D7 to D2009, therefore I won't be
After converting an ASP.NET webform (v3.5) to use a master page, I started getting

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.