nonstandard type for a bit field warning

Collapse
X
 
  • Time
  • Show
Clear All
new posts
  • awagner
    New Member
    • Feb 2009
    • 5

    nonstandard type for a bit field warning

    I am compiling a C application on an HP Unix 11.23 platform using the C99 compiler. I am receiving the following three warning message from the /usr/include/sys/_mbstate_t.h include file.

    "/usr/include/sys/_mbstate_t.h", line 11: warning #2230-D: nonstandard type
    for a bit field
    unsigned char __parse_size:3;
    ^
    "/usr/include/sys/_mbstate_t.h", line 12: warning #2230-D: nonstandard type
    for a bit field
    unsigned char __dummy:4;
    ^
    "/usr/include/sys/_mbstate_t.h", line 13: warning #2230-D: nonstandard type
    for a bit field
    unsigned char __shift_state:1 ;

    I understand that the c99 compiler warns the user of the use of "unsigned char". However, this is in a system include file. Is there a compiler option that will tell the c99 compiler to accept "unsigned char"? I don't want to surpress warning messages and I really don't like to ignore warning messages. Any help will be greatly appreciated.
  • JosAH
    Recognized Expert MVP
    • Mar 2007
    • 11453

    #2
    If that header file comes with your C99 compiler I consider that a sloppy blooper. If not, it's not the (old) header file to blame. Bit fields can be of type (un)signed int or Bool, nothing else. If I had to work with this struct I'd check if the packing of the bits works out ok (including the warnings) and ignore those warnings if everthing works out fine. Otherwise, complain at HP.

    kind regards,

    Jos

    Comment

    • awagner
      New Member
      • Feb 2009
      • 5

      #3
      Thank you for your assistance. I have both the C89 compiler and the C99 compiler. I have been using the C89 compiler for years and would like to use the C99 compiler since it seems to warn me more than the C89 compiler on potential problems. The include file listed above comes with the system. It is not one from our development team and I agree --- very sloppy.

      Comment

      • awagner
        New Member
        • Feb 2009
        • 5

        #4
        I asked this question on the HP forum and received the following response from HP. The suggestions worked.

        <begin response>
        What version of aC++ are you using?
        The only way you can get that warning on system include files is if you are illegally including the default include path, -I/usr/include. Remove it.

        >Is there a compiler option that will tell the c99 compiler to accept "unsigned char"?

        The compiler does accept it. By using c99 instead of "cc -AC99", you are asking to get that warning.
        You can suppress warning 2230 with +W2230.
        <end response>

        Comment

        • Banfa
          Recognized Expert Expert
          • Feb 2006
          • 9067

          #5
          Remember that by suppressing the warning all you are doing is masking the problem rather than fixing it.

          The HP might accept unsigned char but by using it you are creating non-standard, non-portable code that could be an issue if your product is ever moved to another platform.

          Comment

          • JosAH
            Recognized Expert MVP
            • Mar 2007
            • 11453

            #6
            Originally posted by awagner
            The only way you can get that warning on system include files is if you are illegally including the default include path, -I/usr/include. Remove it.
            Cute; you're not supposed to use the standard system include files; does that compiler come with its own header files, compatible with the system header files?

            kind regards,

            Jos

            Comment

            • awagner
              New Member
              • Feb 2009
              • 5

              #7
              Originally posted by JosAH
              Cute; you're not supposed to use the standard system include files; does that compiler come with its own header files, compatible with the system header files?

              kind regards,

              Jos
              Yes cute. Apparently the header files do come with the compiler. I removed the -I/usr/include and changed the "c99" compiler to "cc -AC99" as suggested in our makefiles. I did not suppress the warning. I don't like doing that.

              Comment

              • JosAH
                Recognized Expert MVP
                • Mar 2007
                • 11453

                #8
                Originally posted by awagner
                Yes cute. Apparently the header files do come with the compiler. I removed the -I/usr/include and changed the "c99" compiler to "cc -AC99" as suggested in our makefiles. I did not suppress the warning. I don't like doing that.
                I suspect that the warning is still issued? The trouble with those bitfields is packing; I suspect that this happens with unsigned char bitfiields:

                Code:
                struct {
                   unsigned char foo:6;
                   unsigned char bar:3;
                }
                The structure supposedly looks like this:
                FFFFFFxxBBBxxxx x

                i.e. 6 bits for member foo; foo is packed in a byte and field bar is packed in the next byte. OTOH I suspect the structure:

                Code:
                struct {
                   unsigned int foo:6;
                   unsigned int bar;3;
                }
                ... to be packed as follows:
                FFFFFFBBBxxxxxx x ... sixteen bits more ...

                i.e. both member fields fit in a single int. You have to check how the stuff is packed while that warning is issued.

                kind regards,

                Jos

                Comment

                • awagner
                  New Member
                  • Feb 2009
                  • 5

                  #9
                  My apologies for not being clear. No, the warning is no longer issued after I made the suggested coding changed.

                  Comment

                  • JosAH
                    Recognized Expert MVP
                    • Mar 2007
                    • 11453

                    #10
                    Originally posted by awagner
                    My apologies for not being clear. No, the warning is no longer issued after I made the suggested coding changed.
                    I guess all you can do now is check if it works, i.e. see if the packing of the bit fields is done correctly (read: as you want it to be done). Best of luck.

                    kind regards,

                    Jos

                    Comment

                    Working...