CodeGuru Home VC++ / MFC / C++ .NET / C# Visual Basic VB Forums Developer.com
Results 1 to 4 of 4
  1. #1
    Join Date
    Apr 2003
    Location
    mumbai
    Posts
    18

    Wink off set in structure or class size.

    How the off set are set while allocating memory.
    calss A()
    {
    public:
    char a[10];
    char b[2];
    float c;
    };


    calss B()
    {
    public:
    char a[10];
    float c;
    char b[2];
    };

    int aa=sizeof(A)// returns 16 bytes
    int aa=sizeof(B)// returns 20 bytes

    how the offsets are defined in structure and classes.

    Thanks.
    sanjiv

  2. #2
    Join Date
    Apr 1999
    Location
    Altrincham, England
    Posts
    4,470
    It's dependent on the compiler that you use. It's rarely relevant, anyway.
    Correct is better than fast. Simple is better than complex. Clear is better than cute. Safe is better than insecure.
    --
    Sutter and Alexandrescu, C++ Coding Standards

    Programs must be written for people to read, and only incidentally for machines to execute.

    --
    Harold Abelson and Gerald Jay Sussman

    The cheapest, fastest and most reliable components of a computer system are those that aren't there.
    -- Gordon Bell


  3. #3
    Join Date
    Dec 2001
    Location
    Ontario, Canada
    Posts
    2,236
    Its configured by the "struct member alignment" settings. Search for this topic if you need more information.

  4. #4
    Join Date
    Apr 2003
    Location
    mumbai
    Posts
    18

    Thumbs up Thanks

    Thanks mwilliamson
    I got it .
    sanjiv

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  





Click Here to Expand Forum to Full Width

Featured