PDA

View Full Version : syntax error



Unregistered
02-13-2002, 07:01 AM
why am i getting the error
synatx error before ":"

void main()
{
int i:3;
}


now when in memory what will be the size of the integer will it be of 4 bytes or will it take 3 bits actually.


also if i have to use similar ones like int i:3,j:4:k:1

now how do i access i,j,k individually

alex
02-13-2002, 07:21 AM
You can only use bit fields in structs (that's way the compiler complains about a syntax error):



struct MYBITFIELD
{
unsigned int i:3;
unsigned int j:4;
unsigned int k:1;
}
bit;

you can access these fields using the dot "." operator: bit.i

The amount of memory used depends on the compiler, but usually the components of the bitfield are packed in units of size "sizeof(int)".

alex