> Is there a way to declare a field of a struct as a 24-bit integer in
> GCC?
Well, I think there is: as you wrote it down.

Write a simple example function and compile it with your options, but instead 
of using "-c" (for compiling) please use "-S" (for stop after generating 
assembler). The output file contains the assembler code which you can examine 
for correct working.

My suggestion is this source:

typedef struct {
  int a:1;
  int b:3;
  long c:24;
} T __attribute__((packed));

int get_size(void) {
  return sizeof(T);
}

int get_a(T *t) {
  return t->a;
}

int get_b(T *t) {
  return t->c;
}

long get_c(T *t) {
  return t->c;
}

> Barring that, do I have any guarantees about the order and
> packing of bitfields,
The standard (ISO) does _NOT_ guarantee order or packing. You may want to tag 
your source with an "#ifdef" for the compiler. And you need the attribute 
like shown above to get the elements packed, please see the GCC 
documentation.

HTH, Bodo


-- 
For information on using the ACCESS Developer Forums, or to unsubscribe, please 
see http://www.access-company.com/developers/forums/

Reply via email to