Skip to content
  • Categories
  • Recent
  • Tags
  • Popular
  • World
  • Users
  • Groups
Skins
  • Light
  • Cerulean
  • Cosmo
  • Flatly
  • Journal
  • Litera
  • Lumen
  • Lux
  • Materia
  • Minty
  • Morph
  • Pulse
  • Sandstone
  • Simplex
  • Sketchy
  • Spacelab
  • United
  • Yeti
  • Zephyr
  • Dark
  • Cyborg
  • Darkly
  • Quartz
  • Slate
  • Solar
  • Superhero
  • Vapor

  • Default (No Skin)
  • No Skin
Collapse
Code Project
  1. Home
  2. General Programming
  3. C / C++ / MFC
  4. can anybody tell me why the size of the class is 16

can anybody tell me why the size of the class is 16

Scheduled Pinned Locked Moved C / C++ / MFC
3 Posts 3 Posters 0 Views 1 Watching
  • Oldest to Newest
  • Newest to Oldest
  • Most Votes
Reply
  • Reply as topic
Log in to reply
This topic has been deleted. Only users with topic management privileges can see it.
  • P Offline
    P Offline
    philiptabraham
    wrote on last edited by
    #1

    i have a class as mentioned below.The size of the class is only 16.Can anybody give me an explanation for this.Is this because of padding class EXP { char c1; char c2; int i1; int i2; char *ptr; static int mem; }; THANKS IN ADVANCE

    M H 2 Replies Last reply
    0
    • P philiptabraham

      i have a class as mentioned below.The size of the class is only 16.Can anybody give me an explanation for this.Is this because of padding class EXP { char c1; char c2; int i1; int i2; char *ptr; static int mem; }; THANKS IN ADVANCE

      M Offline
      M Offline
      Maxwell Chen
      wrote on last edited by
      #2

      There are "paddings" between some members of a structure. This is for convenience for the CPU to access. But you can change the padding size. To view the positions and the sizes of paddings, you can list the addresses of each members as below.

      EXP obj;
      printf("obj.c1: 0x%p \nobj.c2: 0x%p \nobj.i1: 0x%p \n", &obj.c1, &obj.c2, &obj.i1);


      Maxwell Chen

      1 Reply Last reply
      0
      • P philiptabraham

        i have a class as mentioned below.The size of the class is only 16.Can anybody give me an explanation for this.Is this because of padding class EXP { char c1; char c2; int i1; int i2; char *ptr; static int mem; }; THANKS IN ADVANCE

        H Offline
        H Offline
        Haroon Sarwar
        wrote on last edited by
        #3

        http://en.wikipedia.org/wiki/Data_structure_alignment[^] http://msdn2.microsoft.com/en-us/library/xh3e3fd0(VS.80).aspx[^]

        1 Reply Last reply
        0
        Reply
        • Reply as topic
        Log in to reply
        • Oldest to Newest
        • Newest to Oldest
        • Most Votes


        • Login

        • Don't have an account? Register

        • Login or register to search.
        • First post
          Last post
        0
        • Categories
        • Recent
        • Tags
        • Popular
        • World
        • Users
        • Groups