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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 28, 20262026-05-28T11:19:34+00:00 2026-05-28T11:19:34+00:00

How do you initialize the values of the following struct in a constructor to

  • 0

How do you initialize the values of the following struct in a constructor to defined values?

Both options shown in my code example seem to be a bit ugly….

struct T_AnlagenInfo01
{   
    // Option A
    T_AnlagenInfo01() : fReserve80_0(0), fReserve80_1(0),.... {}; 

    // Option B
    T_AnlagenInfo01()
    { 
        memset(this, 0, sizeof(T_AnlagenInfo01));
    } 

    unsigned long fReserve80_0                          : 1;        
    unsigned long fReserve80_1                          : 1;        
    unsigned long fReserve80_2                          : 1;        
    unsigned long fReserve80_3                          : 1;        
    unsigned long fReserve80_4                          : 1;
    unsigned long fReserve80_5                          : 1;
    unsigned long fReserve80_6                          : 1;
    unsigned long fReserve80_7                          : 1;

    unsigned long fReserve81_0                          : 1;        // 81   
    unsigned long fReserve81_1                          : 1;        
    unsigned long fReserve81_2                          : 1;        
    unsigned long fReserve81_3                          : 1;
    unsigned long fReserve81_4                          : 1;
    unsigned long fReserve81_5                          : 1;
    unsigned long fReserve81_6                          : 1;
    unsigned long fReserve81_7                          : 1;
};
  • 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-28T11:19:35+00:00Added an answer on May 28, 2026 at 11:19 am

    One obvious solution would be to put all of the bits in a separate
    structure, which is a member of your structure, and copy initialize that
    from a static member, e.g.:

    struct T_AnlagenInfo01
    {
        struct Bits
        {
            unsigned long fReserve80_0 : 1;
            unsigned long fReserve80_1 : 1;
            //  ...
        };
        Bits myBits;
        static Bits initialBits;
    
        T_AnlagenInfo01 : myBits(initialBits) {}
    };
    
    T_AnlagenInfo01::Bits T_AnlagenInfo01::initialBits = {};
    

    This would even allow for certain bits to have a value different from 0.

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

Sidebar

Related Questions

Assume there is a cell array initialized with the following struct values. % Phone
In PHP, you can initialize arrays with values quickly using the following notation: $array
The following code is illegal: public struct MyStruct { public MyStruct(int a, int b)
The following code: #include <vector> struct S { int x, y; }; int main()
I have defined the following select list: <%= this.Select(Scope) .Options(Scopes.AllValues) // static property to
I have the following struct in my C++ code (I am using Visual Studio
In the following code, initialize() illustrates a method based on compile-time polymorphism. The version
I wrote the following code snippet: void foo() { struct _bar_ { int a;
Is it a good practice to initialize columns that we can know their values
I have the following types: struct X { int x; X( int val )

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.