Re: C parse error, why?
- From: "Glenn Hutchings" <zondo pillock freeserve co uk>
- To: <gtk-list gnome org>
- Subject: Re: C parse error, why?
- Date: Sat, 26 Aug 2000 12:43:20 +0100
-----Original Message-----
From: Nengming Zhang <znm@china.com>
To: gtk-list@gnome.org <gtk-list@gnome.org>
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
[
Date Prev][
Date Next] [
Thread Prev][
Thread Next]
[
Thread Index]
[
Date Index]
[
Author Index]