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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 16, 20262026-05-16T09:07:14+00:00 2026-05-16T09:07:14+00:00

I got a structure like this: struct bar { char x; char *y; };

  • 0

I got a structure like this:

struct bar {
    char x;
    char *y;
};

I can assume that on a 32 bit system, that padding for char will make it 4 bytes total, and a pointer in 32 bit is 4, so the total size will be 8 right?

I know it’s all implementation specific, but I think if it’s within 1-4, it should be padded to 4, within 5-8 to 8 and 9-16 within 16, is this right? it seems to work.

Would I be right to say that the struct will be 12 bytes in a x64 arch, because pointers are 8 bytes? Or what do you think it should be?

  • 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-16T09:07:15+00:00Added an answer on May 16, 2026 at 9:07 am

    I can assume that on a 32 bit system,
    that padding for char will make it 4
    bytes total, and a pointer in 32 bit
    is 4, so the total size will be 8
    right?

    It’s not safe to assume that, but that will often be the case, yes. For x86, fields are usually 32-bit aligned. The reason for this is to increase the system’s performance at the cost of memory usage (see here).

    Would I be right to say that the
    struct will be 12 bytes in a x64 arch,
    because pointers are 8 bytes? Or what
    do you think it should be?

    Similarly, for x64, fields are usually 64-bit/8-byte aligned, so sizeof(bar) would be 16.

    As Anders points out, however, all this goes flying out the window once you start playing with alignment via /Zp, the pack directive, or whatever else your compiler supports.

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

Sidebar

Related Questions

Wow now i know I dont. Lol. I've got my structure like this: struct
I've got a structure defined inside header.h that looks like : typedef struct {
I've got MongoKit structure like this: structure = { ... 'plugin': { 'id': unicode,
I've got an xml structure similar to this: <cars> <car> <make>Ford</make> <model>F-150</model> <year>2011</year> <customs>
I got a really simple table structure like this: Table Page Hits id |
I've got some sections in my .vimrc that look like this: autocmd Filetype ruby
I've got a tree-like structure. Each element in this structure should be able to
suppose a struct defined like this: struct S{ char a[3]; char b[3]; char c[3];
Let's say you've got a Spring web app with a structure like this: com/
I've got a structure set up like this: <div id=container> <div class=child></div> <div class=child></div>

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.