C
Claudio
hi all
i put in this email source code so u can copy and paste to verify strange
first : in this example bit size is a BYTE ?!
second : in the last printf output is wrong ?
?
best regards all
#include <stdio.h>
int main ( void )
{
struct snibble
{
unsigned a : 1 ;
unsigned b : 1 ;
unsigned c : 1 ;
unsigned d : 1 ;
} ;
struct sbyte
{
struct snibble high ;
struct snibble low ;
} ;
union ubyte
{
struct sbyte a ;
char c ;
} ;
struct snibble n ;
struct sbyte sb ;
union ubyte ub ;
printf ("\n %u " , sizeof ( ub ) ) ;
printf ("\n %u " , sizeof ( sb ) ) ;
printf ("\n %u " , sizeof ( n ) ) ;
printf ("\n %u " , sizeof ( char ) ) ;
ub.c = 'a' ;
printf ("\n\n %c " , ub.c ) ;
printf ("\n %u " , ub.a.high ) ;
printf ("\n %u " , ub.a.low ) ;
}
i put in this email source code so u can copy and paste to verify strange
first : in this example bit size is a BYTE ?!
second : in the last printf output is wrong ?
?
best regards all
#include <stdio.h>
int main ( void )
{
struct snibble
{
unsigned a : 1 ;
unsigned b : 1 ;
unsigned c : 1 ;
unsigned d : 1 ;
} ;
struct sbyte
{
struct snibble high ;
struct snibble low ;
} ;
union ubyte
{
struct sbyte a ;
char c ;
} ;
struct snibble n ;
struct sbyte sb ;
union ubyte ub ;
printf ("\n %u " , sizeof ( ub ) ) ;
printf ("\n %u " , sizeof ( sb ) ) ;
printf ("\n %u " , sizeof ( n ) ) ;
printf ("\n %u " , sizeof ( char ) ) ;
ub.c = 'a' ;
printf ("\n\n %c " , ub.c ) ;
printf ("\n %u " , ub.a.high ) ;
printf ("\n %u " , ub.a.low ) ;
}