Results 1 to 12 of 12

Thread: Sizeof wrong with structures ?????

Threaded View

Previous Post Previous Post   Next Post Next Post
  1. #1
    Join Date
    Sep 2010
    Posts
    654
    Thanks
    56
    Thanked 1 Time in 1 Post
    Qt products
    Qt4
    Platforms
    Windows

    Default Sizeof wrong with structures ?????

    Qt Code:
    1. struct AA {
    2. float a;
    3. float b;
    4. unsigned char metadata;
    5. };
    To copy to clipboard, switch view to plain text mode 
    The size of this are 4+4+1 , isn't it ?

    AA *aa = new AA;
    sizeof *aa = 12 ?????

    Qt Code:
    1. struct AA {
    2. float a;
    3. float b;
    4. float c;
    5. float d;
    6. float e;
    7. short int c1;
    8. short int c2;
    9. };
    To copy to clipboard, switch view to plain text mode 
    5*4 +4+4 = 28
    sizeof *aa = 24 ?????

    And I could show more errors .
    What is happen ?

    I have read something related to pragma option
    Y
    our compiler may have a "#pragma option" feature that you can use to
    wrap your structure definition, to enforce the byte alignment you want.
    You have to refer to your documentation for details.
    How to do this witn Qt + mingw ?


    Thanks
    Last edited by tonnot; 27th June 2011 at 14:32.

Similar Threads

  1. convert from QString to char[sizeof(...)]
    By adamatic in forum Qt Programming
    Replies: 4
    Last Post: 3rd September 2011, 09:05
  2. Replies: 5
    Last Post: 23rd June 2011, 08:31
  3. What do I do wrong
    By Arif Bilgin in forum Newbie
    Replies: 12
    Last Post: 20th October 2010, 20:03
  4. i don't know what i do wrong..
    By Hardstyle in forum Newbie
    Replies: 2
    Last Post: 27th June 2010, 17:33
  5. which one is constant,sizeof(int) or sizeof(long)?
    By coralbird in forum Qt Programming
    Replies: 4
    Last Post: 20th March 2006, 11:01

Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  
Qt is a trademark of The Qt Company.