bit array in C++

Collapse
This topic is closed.
X
X
 
  • Time
  • Show
Clear All
new posts
  • hondya

    #1

    bit array in C++

    The following piece of code compiles under C (gcc 3.4.2)

    typedef struct {
    unsigned int padding[16]:1;
    unsigned int holes[16]:1;
    } triangle_bitmap _t;

    However I get the error "invalid member function declaration" when I
    try to compile it with C++ compiler (g++ 3.4.2). Any idea what might I
    be doing wrong.

  • Ron Natalie

    #2
    Re: bit array in C++

    hondya wrote:[color=blue]
    > The following piece of code compiles under C (gcc 3.4.2)
    >
    > typedef struct {
    > unsigned int padding[16]:1;
    > unsigned int holes[16]:1;
    > } triangle_bitmap _t;
    >
    > However I get the error "invalid member function declaration" when I
    > try to compile it with C++ compiler (g++ 3.4.2). Any idea what might I
    > be doing wrong.
    >[/color]
    The error is a bit obtuse, but there is no such thing as a bit array.
    A bitfield identifier must either be applied directly to the identifier
    name or be an unnamed one. You can't apply it to an array .

    Comment

    • hondya

      #3
      Re: bit array in C++

      Is it a C++ limitation/bug? Because the same thing works in C.

      Comment

      • Neelesh Bodas

        #4
        Re: bit array in C++


        hondya wrote:[color=blue]
        > Is it a C++ limitation/bug?[/color]
        No, its a syntax error. Bitfields cannot be applied for arrays.

        [color=blue][color=green]
        >> the same thing works in C.[/color][/color]

        C is not C++ and C++ is not C.

        Comment

        • Default User

          #5
          Re: bit array in C++

          hondya wrote:
          [color=blue]
          > Is it a C++ limitation/bug? Because the same thing works in C.[/color]

          It's illegal in C as well. If your C compiler allowed, then it is some
          sort of extension.



          Brian

          --
          Please quote enough of the previous message for context. To do so from
          Google, click "show options" and use the Reply shown in the expanded
          header.

          Comment

          • PaweÅ‚

            #6
            Re: bit array in C++

            hondya wrote:
            [color=blue]
            > The following piece of code compiles under C (gcc 3.4.2)[/color]

            gcc 3.4.5 reject this code with error: bit-field `...' has invalid type.

            Comment

            Working...