<html><head><style type="text/css"><!-- DIV {margin:0px;} --></style></head><body><div style="font-family:times new roman, new york, times, serif;font-size:12pt"><DIV style="FONT-SIZE: 12pt; FONT-FAMILY: times new roman, new york, times, serif">
<DIV style="FONT-SIZE: 12pt; FONT-FAMILY: times new roman, new york, times, serif">
<DIV style="FONT-SIZE: 12pt; FONT-FAMILY: times new roman, new york, times, serif">
<DIV style="FONT-SIZE: 12pt; FONT-FAMILY: times new roman, new york, times, serif">
<DIV style="FONT-SIZE: 12pt; FONT-FAMILY: times new roman, new york, times, serif">
<DIV style="FONT-SIZE: 12pt; FONT-FAMILY: times new roman, new york, times, serif">
<DIV style="FONT-SIZE: 12pt; FONT-FAMILY: times new roman, new york, times, serif">
<DIV style="FONT-SIZE: 12pt; FONT-FAMILY: times new roman, new york, times, serif">
<DIV style="FONT-SIZE: 12pt; FONT-FAMILY: times new roman, new york, times, serif">
<DIV style="FONT-SIZE: 12pt; FONT-FAMILY: times new roman, new york, times, serif">
<DIV style="FONT-SIZE: 12pt; FONT-FAMILY: times new roman, new york, times, serif">
<DIV style="FONT-SIZE: 12pt; FONT-FAMILY: times new roman, new york, times, serif">
<DIV>Hola amigos, soy yo otra vez. Quería que me ayudarais con unas dudas que tengo en los campos de bits:</DIV>
<P> </P>
<P>En una estructura como esta:</P>
<P><FONT face="tahoma, new york, times, serif" color=#0000ff></FONT> </P>
<P><FONT face="tahoma, new york, times, serif" color=#0000ff>struct Bits</FONT></P>
<P><FONT face="tahoma, new york, times, serif" color=#0000ff>{<BR>       unsigned short bit1:5;//Variable unsigned short de 5 bits<BR>       unsigned short bit2:4;//Variable unsigned short de 4 bits<BR>       unsigned short bit3:7;//Variable unsigned short de 7 bits<BR>}Param[10];</FONT></P>
<P> </P>
<P>Si luego uso esta sentencia:</P>
<P> </P>
<P><FONT face="tahoma, new york, times, serif" color=#0000ff>cout << sizeof(Bits);</FONT></P>
<P><FONT face=Tahoma color=#0000ff></FONT> </P>
<P><FONT face="times new roman, new york, times, serif">Lo que aparece en pantalla es 2. Yo supuse que aparecería 3 porque, según se explica:</FONT></P>
<P> </P>
<P>Bits |    0    1    2    3    4    5    6    7   || 8    9    10    11    12    13    14    15 ||   16    17    18    19    20    21    22    23  ||  24</P>
<P>_________________________________________________________________________________________________</P>
<P>Var |  unsigned short bit 1 ||    Vacío    ||            bit2        ||          Vacío            ||                        bit4                            || Vacío</P>
<P> </P>
<P>Según esto, la estructura debería ocupar 3 bytes y no 2. ¿Por qué entonces pone que ocupa 2?</P>
<P> </P>
<P> </P>
<P>2ª Pregunta: En la misma estructura, si luego uso este bucle:</P>
<P> </P>
<P><FONT color=#0000ff> </FONT><FONT face="tahoma, new york, times, serif" color=#0000ff>for(k = 0; k < 10; k++)<BR>    {<BR>          cin >> Param[k].bit1;<BR>          cin >> Param[k].bit2;<BR>          cin >> Param[k].bit3;<BR>     }</FONT></P>
<P><FONT face=Tahoma color=#0000ff></FONT> </P>
<P><FONT face="times new roman, new york, times, serif">A continuación el compilador me da un error para cada una de las lineas donde escribo los "cin >> ". Pone algo así:</FONT></P>
<P><FONT color=#ff0000>"In function 'int main()':</FONT></P>
<P><FONT color=#ff0000>cannot bind bitfield 'Param[k].Bits::bit1' to 'short unsigned int&'</FONT></P>
<P><FONT color=#ff0000>cannot bind bitfield 'Param[k].Bits::bit2' to 'short unsigned int&'</FONT></P>
<P><FONT color=#ff0000>cannot bind bitfield 'Param[k].Bits::bit3' to 'short unsigned int&'</FONT></P>
<P>¿Qué está pasando y cómo lo puedo solucionar?</P>
<P> </P>
<P>Un saludo y gracias por vuestra ayuda, Alejandro.</P></DIV><BR>
<HR SIZE=1>
<BR><FONT face=Verdana size=-2>LLama Gratis a cualquier PC del Mundo.<BR>Llamadas a fijos y móviles desde 1 céntimo por minuto.<BR><A href="http://us.rd.yahoo.com/mail/es/tagline/messenger/*http://es.voice.yahoo.com/" target=_blank rel=nofollow>http://es.voice.yahoo.com</A></FONT></DIV><BR></DIV></DIV><BR>
<HR SIZE=1>
<BR><FONT face=Verdana size=-2>LLama Gratis a cualquier PC del Mundo.<BR>Llamadas a fijos y móviles desde 1 céntimo por minuto.<BR><A href="http://us.rd.yahoo.com/mail/es/tagline/messenger/*http://es.voice.yahoo.com/" target=_blank rel=nofollow>http://es.voice.yahoo.com</A></FONT></DIV><BR></DIV></DIV><BR>
<HR SIZE=1>
<BR><FONT face=Verdana size=-2>LLama Gratis a cualquier PC del Mundo.<BR>Llamadas a fijos y móviles desde 1 céntimo por minuto.<BR><A href="http://us.rd.yahoo.com/mail/es/tagline/messenger/*http://es.voice.yahoo.com/" target=_blank rel=nofollow>http://es.voice.yahoo.com</A></FONT></DIV><BR></DIV></DIV><BR>
<HR SIZE=1>
<BR><FONT face=Verdana size=-2>LLama Gratis a cualquier PC del Mundo.<BR>Llamadas a fijos y móviles desde 1 céntimo por minuto.<BR><A href="http://us.rd.yahoo.com/mail/es/tagline/messenger/*http://es.voice.yahoo.com/" target=_blank rel=nofollow>http://es.voice.yahoo.com</A></FONT></DIV><BR></DIV></div><br>
                <hr size=1><br><font face="Verdana" size="-2">LLama Gratis a cualquier PC del Mundo.<br>Llamadas a fijos y móviles desde 1 céntimo por minuto.<br><a href="http://us.rd.yahoo.com/mail/es/tagline/messenger/*http://es.voice.yahoo.com/">http://es.voice.yahoo.com</a></font></body></html>