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
CODE PROJECT For Those Who Code
  • Home
  • Articles
  • FAQ
Community
  1. Home
  2. General Programming
  3. C / C++ / MFC
  4. Struct issue

Struct issue

Scheduled Pinned Locked Moved C / C++ / MFC
helptutorialquestion
9 Posts 5 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.
  • A Offline
    A Offline
    Alexander M
    wrote on last edited by
    #1

    how to make clear that this struct has to be 2 bytes in size and NOT 3?

    typedef struct _TEST
    {
    USHORT FragmentOffset: 13;
    UCHAR MF: 1;
    UCHAR DF: 1;
    UCHAR Reserved: 1;
    } TEST, *PTEST;

    Thanks Don't try it, just do it! ;-)

    V J A 3 Replies Last reply
    0
    • A Alexander M

      how to make clear that this struct has to be 2 bytes in size and NOT 3?

      typedef struct _TEST
      {
      USHORT FragmentOffset: 13;
      UCHAR MF: 1;
      UCHAR DF: 1;
      UCHAR Reserved: 1;
      } TEST, *PTEST;

      Thanks Don't try it, just do it! ;-)

      V Offline
      V Offline
      Vitali Halershtein
      wrote on last edited by
      #2

      Hi, try to sizeof(...) = 4 ;) Vitali http://www.creative-case.com

      A 1 Reply Last reply
      0
      • A Alexander M

        how to make clear that this struct has to be 2 bytes in size and NOT 3?

        typedef struct _TEST
        {
        USHORT FragmentOffset: 13;
        UCHAR MF: 1;
        UCHAR DF: 1;
        UCHAR Reserved: 1;
        } TEST, *PTEST;

        Thanks Don't try it, just do it! ;-)

        J Offline
        J Offline
        John M Drescher
        wrote on last edited by
        #3

        Use #pragma pack John

        A 1 Reply Last reply
        0
        • J John M Drescher

          Use #pragma pack John

          A Offline
          A Offline
          Alexander M
          wrote on last edited by
          #4

          I did, but it doesn't work. Don't try it, just do it! ;-)

          J 1 Reply Last reply
          0
          • V Vitali Halershtein

            Hi, try to sizeof(...) = 4 ;) Vitali http://www.creative-case.com

            A Offline
            A Offline
            Alexander M
            wrote on last edited by
            #5

            I can't, this struct is part of the IPv4 header. Don't try it, just do it! ;-)

            1 Reply Last reply
            0
            • A Alexander M

              I did, but it doesn't work. Don't try it, just do it! ;-)

              J Offline
              J Offline
              John M Drescher
              wrote on last edited by
              #6

              How about making all the UCHARs to USHORT? John

              A M 2 Replies Last reply
              0
              • J John M Drescher

                How about making all the UCHARs to USHORT? John

                A Offline
                A Offline
                Alexander M
                wrote on last edited by
                #7

                Thank you John, that works! Don't try it, just do it! ;-)

                1 Reply Last reply
                0
                • J John M Drescher

                  How about making all the UCHARs to USHORT? John

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

                  Yes, you are right. But how strange ... although I remembered that in C++ syntax, we only have to write this way for bit field:

                  struct SS
                  {
                  unsigned A : 13;
                  unsigned B : 1;
                  unsigned C : 1;
                  unsigned D : 1;
                  }; // size = 4.

                  But with pragma of VisualC++7, the previous acts different to:

                  struct SS
                  {
                  unsigned short A : 13;
                  unsigned short B : 1;
                  unsigned short C : 1;
                  unsigned short D : 1;
                  }; // size = 2.

                  Maxwell Chen

                  1 Reply Last reply
                  0
                  • A Alexander M

                    how to make clear that this struct has to be 2 bytes in size and NOT 3?

                    typedef struct _TEST
                    {
                    USHORT FragmentOffset: 13;
                    UCHAR MF: 1;
                    UCHAR DF: 1;
                    UCHAR Reserved: 1;
                    } TEST, *PTEST;

                    Thanks Don't try it, just do it! ;-)

                    A Offline
                    A Offline
                    Anonymous
                    wrote on last edited by
                    #9

                    Hi If you have problems with the size structue you have to close your structure declaration between #pragma pack() instruction, you can get additional info at msdn.

                    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