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. What is this ':'?

What is this ':'?

Scheduled Pinned Locked Moved C / C++ / MFC
questionc++saleshelp
9 Posts 2 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.
  • S Offline
    S Offline
    Sam C
    wrote on last edited by
    #1

    Ok I know this might sound stupid but I have to find out. I have recently come across code that does this:

    unsigned int len:4;

    What does the semicolon signify? I have not seen this type of "shortcut" using C++. I have been scouring through all the literature I have on C++ and can't find it so in taking the chance of sounding stupid I must ask this question. What is this signifying a value? Or is it a bit designation saying use 4 bits instead of 4 bytes to represent this value? Please help I am going crazy trying to figure this out... btw, please refrain from answer that this is a semicolon :-) I know many of you are urged to do so . Sam C ---- Systems Manager Hospitality Marketing Associates

    C 1 Reply Last reply
    0
    • S Sam C

      Ok I know this might sound stupid but I have to find out. I have recently come across code that does this:

      unsigned int len:4;

      What does the semicolon signify? I have not seen this type of "shortcut" using C++. I have been scouring through all the literature I have on C++ and can't find it so in taking the chance of sounding stupid I must ask this question. What is this signifying a value? Or is it a bit designation saying use 4 bits instead of 4 bytes to represent this value? Please help I am going crazy trying to figure this out... btw, please refrain from answer that this is a semicolon :-) I know many of you are urged to do so . Sam C ---- Systems Manager Hospitality Marketing Associates

      C Offline
      C Offline
      Chris Losinger
      wrote on last edited by
      #2

      it's a colon. actually, it's a 'bitfield' specification, used to set a specific bit position for data within a struct or union. from the MSDN:

      This example defines a two-dimensional array of structures named screen.

      struct
      {
      unsigned short icon : 8;
      unsigned short color : 4;
      unsigned short underline : 1;
      unsigned short blink : 1;
      } screen[25][80];

      The array contains 2,000 elements. Each element is an individual structure containing four bit-field members: icon, color, underline, and blink. The size of each structure is two bytes.

      Bit fields have the same semantics as the integer type. This means a bit field is used in expressions in exactly the same way as a variable of the same base type would be used, regardless of how many bits are in the bit field.

      -c ------------------------------ Smaller Animals Software, Inc. http://www.smalleranimals.com

      S 1 Reply Last reply
      0
      • C Chris Losinger

        it's a colon. actually, it's a 'bitfield' specification, used to set a specific bit position for data within a struct or union. from the MSDN:

        This example defines a two-dimensional array of structures named screen.

        struct
        {
        unsigned short icon : 8;
        unsigned short color : 4;
        unsigned short underline : 1;
        unsigned short blink : 1;
        } screen[25][80];

        The array contains 2,000 elements. Each element is an individual structure containing four bit-field members: icon, color, underline, and blink. The size of each structure is two bytes.

        Bit fields have the same semantics as the integer type. This means a bit field is used in expressions in exactly the same way as a variable of the same base type would be used, regardless of how many bits are in the bit field.

        -c ------------------------------ Smaller Animals Software, Inc. http://www.smalleranimals.com

        S Offline
        S Offline
        Sam C
        wrote on last edited by
        #3

        Thanks, Chris, and you're right it is a colon :-) Is there and MSDN article or knowledgbase number you can refer me too? Doing a search for bitfield specification brings up nothing we'll things I can't make sense of. Basically, I just want to see if they have an example, like:

        struct Length
        {
        unsigned short begin:4;
        unsigned short end:4;
        };

        Does this designate the structure to be a size of 1 byte (4 bits * 2) or is it still a 4 byte structure, in which you do a read in it will only ready the first 1 byte of data? For example, we have a binary data that looks like this: 00001111000000000000000000000000 <= 4 bytes long we read it into our LENGTH struct is it now read as: begin = 00001111 end = 00000000 extra bits are ignored. or is read like this: begin = 0000111100000000 end = 0000000000000000 Thanks for the quick answer, and I hope I'm not annoying anyone :-) Sam C ---- Systems Manager Hospitality Marketing Associates

        C 1 Reply Last reply
        0
        • S Sam C

          Thanks, Chris, and you're right it is a colon :-) Is there and MSDN article or knowledgbase number you can refer me too? Doing a search for bitfield specification brings up nothing we'll things I can't make sense of. Basically, I just want to see if they have an example, like:

          struct Length
          {
          unsigned short begin:4;
          unsigned short end:4;
          };

          Does this designate the structure to be a size of 1 byte (4 bits * 2) or is it still a 4 byte structure, in which you do a read in it will only ready the first 1 byte of data? For example, we have a binary data that looks like this: 00001111000000000000000000000000 <= 4 bytes long we read it into our LENGTH struct is it now read as: begin = 00001111 end = 00000000 extra bits are ignored. or is read like this: begin = 0000111100000000 end = 0000000000000000 Thanks for the quick answer, and I hope I'm not annoying anyone :-) Sam C ---- Systems Manager Hospitality Marketing Associates

          C Offline
          C Offline
          Chris Losinger
          wrote on last edited by
          #4

          an MSDN search on "bitfield struct" gives a ton of articles. but the first one that comes up for me is titled "INFO: Initializing Bitfields as Integers in C" is has some sample code. not annoying me... i'd forgotten all about the mysterious bitfield stuff. now, thanks to your question, i have another bit (pun intended) of C trivia to impress people with. :) -c ------------------------------ Smaller Animals Software, Inc. http://www.smalleranimals.com

          S 1 Reply Last reply
          0
          • C Chris Losinger

            an MSDN search on "bitfield struct" gives a ton of articles. but the first one that comes up for me is titled "INFO: Initializing Bitfields as Integers in C" is has some sample code. not annoying me... i'd forgotten all about the mysterious bitfield stuff. now, thanks to your question, i have another bit (pun intended) of C trivia to impress people with. :) -c ------------------------------ Smaller Animals Software, Inc. http://www.smalleranimals.com

            S Offline
            S Offline
            Sam C
            wrote on last edited by
            #5

            Thanks, Chris! That sort of explained it, I'm just going to brute force the rest and add a strucutre with that information an dthen add it to watch and see what values are assigned to each member variable :-) Btw, did you get my email, I am definetly looking forward to a reply. I am very interested in your IMGDLL file on our website and had a couple of questions basically, what is the size of the DLL if you do a static link how much does that add to my final EXE. Maybe you may want to post that information here so others can view it, but for someone who created non-DB applications that are not part of work you can't beat the value on that piece of software :-) Sam C ---- Systems Manager Hospitality Marketing Associates

            C 1 Reply Last reply
            0
            • S Sam C

              Thanks, Chris! That sort of explained it, I'm just going to brute force the rest and add a strucutre with that information an dthen add it to watch and see what values are assigned to each member variable :-) Btw, did you get my email, I am definetly looking forward to a reply. I am very interested in your IMGDLL file on our website and had a couple of questions basically, what is the size of the DLL if you do a static link how much does that add to my final EXE. Maybe you may want to post that information here so others can view it, but for someone who created non-DB applications that are not part of work you can't beat the value on that piece of software :-) Sam C ---- Systems Manager Hospitality Marketing Associates

              C Offline
              C Offline
              Chris Losinger
              wrote on last edited by
              #6

              ImgDLL was discontinued a while ago. It was replaced by the even-more-capable ImgSource (http://www.smalleranimals.com/isource.htm). ImgSource does much much more than ImgDLL, and is faster, more stable, easier to use, etc.. static linking to the ImgSource .LIBs adds anywhere from 30K to 700K, depending on which of the functions you pull in; simple image processing stuff gets you just a few K, TIFF support brings in over 300K, JPG is 100K or so, etc.. (sorry, didn't get your mail until late night, CP email notifications were delayed again today, i guess) -c ------------------------------ Smaller Animals Software, Inc. http://www.smalleranimals.com

              S 1 Reply Last reply
              0
              • C Chris Losinger

                ImgDLL was discontinued a while ago. It was replaced by the even-more-capable ImgSource (http://www.smalleranimals.com/isource.htm). ImgSource does much much more than ImgDLL, and is faster, more stable, easier to use, etc.. static linking to the ImgSource .LIBs adds anywhere from 30K to 700K, depending on which of the functions you pull in; simple image processing stuff gets you just a few K, TIFF support brings in over 300K, JPG is 100K or so, etc.. (sorry, didn't get your mail until late night, CP email notifications were delayed again today, i guess) -c ------------------------------ Smaller Animals Software, Inc. http://www.smalleranimals.com

                S Offline
                S Offline
                Sam C
                wrote on last edited by
                #7

                Sorry it is ImgSource, however what is the ImgX product? I see no mention of that on your website, just on the boards, is this the one going for version 5? Sorry, but I am really interested in this product for my own personal library, and is their any licensing issues associated with this control? Is there a license fee associated with any distributed work using this control? But basically what is the difference between ImgX and ImgSource? I don't see a reference to ImgX on your site under Products. Thanks, and sorry about all the questions, but you're product seems very interesting :-) Sam C ---- Systems Manager Hospitality Marketing Associates

                C 1 Reply Last reply
                0
                • S Sam C

                  Sorry it is ImgSource, however what is the ImgX product? I see no mention of that on your website, just on the boards, is this the one going for version 5? Sorry, but I am really interested in this product for my own personal library, and is their any licensing issues associated with this control? Is there a license fee associated with any distributed work using this control? But basically what is the difference between ImgX and ImgSource? I don't see a reference to ImgX on your site under Products. Thanks, and sorry about all the questions, but you're product seems very interesting :-) Sam C ---- Systems Manager Hospitality Marketing Associates

                  C Offline
                  C Offline
                  Chris Losinger
                  wrote on last edited by
                  #8

                  ImgX is a VB wrapper for ImgSource. It is a product from a company called Designer Controls. We share boards because a lot of the ImgX issues are ImgSource issues. There are links to ImgX sites from the boards and from the ImgSource home page. -c ------------------------------ Smaller Animals Software, Inc. http://www.smalleranimals.com

                  S 1 Reply Last reply
                  0
                  • C Chris Losinger

                    ImgX is a VB wrapper for ImgSource. It is a product from a company called Designer Controls. We share boards because a lot of the ImgX issues are ImgSource issues. There are links to ImgX sites from the boards and from the ImgSource home page. -c ------------------------------ Smaller Animals Software, Inc. http://www.smalleranimals.com

                    S Offline
                    S Offline
                    Sam C
                    wrote on last edited by
                    #9

                    Oh a VB control, I'll take a look at ImgSource then :-) It took me a long time to totally ween myself away from VB development. Chris, let me say that if your responses here are any indication of the type of support your provide, and your pricing is that good, you may find yourself having a new customer before the end of the day :-) But first I'm going to try it out and see if I can remeber how to make all the extern calls to DLL functions or is that LoadLib and GetProcessEntryPoint to return function pointers?? Oh, well I'll figure it out and I see that you do offer samples with the download :-) Thanks again Chris for all your help, now I'm going to download and evaluate the library. Sam C ---- Systems Manager Hospitality Marketing Associates

                    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