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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 9, 20262026-06-09T21:43:18+00:00 2026-06-09T21:43:18+00:00

static struct{ unsigned a:5; unsigned b:5; unsigned c:5; unsigned d:5; }v={1,2,3,4}; printf(%d %d %d

  • 0
    static struct{
            unsigned a:5;
            unsigned b:5;
            unsigned c:5;
            unsigned d:5;
    }v={1,2,3,4};

    printf("%d %d %d %d %d",v.a,v.b,v.c,v.d,sizeof(v));

Output is : 1 2 3 4 4

Can someone explain why is the size of this struct 4 ? Shouldn’t it be 16 ?

  • 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-09T21:43:19+00:00Added an answer on June 9, 2026 at 9:43 pm

    You’re using 20 bits which fit nicely in 4 bytes. No need for 16 bytes.

    EDIT

    I think it is actually required that they be packed like that:

    6.7.2.1

    An implementation may allocate any addressable storage unit large
    enough to hold a bit- field. If enough space remains, a bit-field that
    immediately follows another bit-field in a structure shall be packed
    into adjacent bits
    of the same unit

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

Sidebar

Related Questions

static struct Args { char* arg1; unsigned arg2; unsigned arg3; char* arg4; } arg;
I have used bit field with a structure like this, struct { unsigned int
static struct ipv6_devconf ipv6_devconf_dflt __read_mostly = { .forwarding = 0, .hop_limit = IPV6_DEFAULT_HOPLIMIT, .mtu6
Minimal code: // --------inline.h-------- struct X { static inline void foo (); }; #ifdef
// File: InitFirst.h #pragma once template <int val> struct InitFirst { static float s_dividedByThree;
struct X { constexpr static char a1[] = hello; // Okay constexpr static const
typedef struct _ut_slot { ucontext_t uc; .... }*ut_slot; static ut_slot* table; //array of the
I' ve got such a function static ssize_t read_mydevice(struct file *filp, char* buf, size_t
Suppose I have a static function template template<int I> void ft() within a struct
template<typename T> struct AClass { public: template<typename T0> static void AFunc() {} }; template<typename

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.