-----Original Message-----
From: Nengming Zhang <[EMAIL PROTECTED]>
To: [EMAIL PROTECTED] <[EMAIL PROTECTED]>
Date: 26 August 2000 07:16
Subject: C parse error, why?


>
>Sorry to ask this simple question!
>
>I don't do  how ":" works In C program like the following example:
>
>int y:1;                          /*  parse error*/
>struct _Test
>{
>        int x :1;                /* no parse error report*/
>}


The syntax x:1 is used to declare a bitfield -- that is, a way of allocating
less than a single byte for a variable.  The compiler packs bitfield
variables together inside an integral number of bytes, which is why it
doesn't make sense to have a bitfield variable on its own, only as part of a
structure.  For example,

struct _Test {
    int x:4;
    int y:4;
};

The whole structure only occupies 1 byte -- 4 bits are allocated to each
variable.  If the structure only contained the x variable, it would still
occupy a byte -- the last 4 bits would be unused.

Hope this helps,

Glenn


_______________________________________________
gtk-list mailing list
[EMAIL PROTECTED]
http://mail.gnome.org/mailman/listinfo/gtk-list

Reply via email to