Skip to the content ForoHackers
Log inJoin

GCC: cannot take address of bit-field 'on'

CCompilersEmbedded Linux
#18072 · · Quote · Report

GCC me ha soltado cannot take address of bit-field 'on'. Es mi juguete, ni placa ni registro de por medio.

struct Bits { unsigned on : 1; };
struct Bits s = {1};

Luego le he intentado pasar &s.on a la función de al lado. ¿Qué tiene el vecino que no pueda mirar mi humilde bit?

#18180 · · Quote · Report

It can see a copy of the value. A pointer to an unsigned points to an addressable object of that type. Which byte address would you like it to use to mean only that bit?

#18181 · · Quote · Report

Vale. unsigned lamp = s.on; y llama a mi visor con &lamp. Apaga el visor su copia y en la estructura sigue habiendo un 1. Confirmado con el ojo clínico de un señor que acaba de aprender a imprimir dos números.

#18182 · · Quote · Report

entonces la función que le TIENE que cambiar el estado, ¿le pasas s entera? una lámpara que cambia cuando miras me parece válida para una discoteca pero aquí me coinciden mal los turnos.

#18183 · · Quote · Report

Para eso pasé puntero a la estructura a void turn_off(struct Bits *p) { p->on = 0; }. Ahora el original sí da cero. Al de leer le doy el valor. He dejado al pobre vecino sin acceso a la fontanería.

#18184 · · Quote · Report

And don't change the display routine to take an address just because your first draft did. If I'm only drawing a bulb, I'll happily have your one or zero through the letterbox without opening the door.

You are not logged in, so this goes up anonymously: no account, no name and no address is stored with it, and it may carry no link and no image. Log in or join to post under your name. Our web server's logs keep the address and time of every request for up to 14 days; to keep yours out of them, use Tor. To reach the staff in confidence, use the drop. Sign as a returning source (a key kept only in this browser)

Sending takes a few seconds here: your browser first works out a proof of work against spam.

Reply