C++ – invalid conversion from volatile uint8_t* to uint8_t*

avr-gcc, c++

I'm trying to set a library in C++ for AVR. The idea is to have an easy way of configuring what pins you use on each device.
This is the library:

class PINS{public://ATTRIBUTESuint8_t* DDRaddr;uint8_t* PORTaddr;uint8_t* PINaddr;int pinnum;//METHODSvoid usepin(volatile uint8_t *pin, int num);};void PINS::usepin(volatile uint8_t *pin, int num){this->pinnum=num;if(pin==&PORTB){    this->DDRaddr=&DDRB;    this->PINaddr=&PINB;    this->PORTaddr=&PORTB;}if(pin==&PORTC){    this->DDRaddr=&DDRC;    this->PINaddr=&PINC;    this->PORTaddr=&PORTC;}if(pin==&PORTD){    this->DDRaddr=&DDRD;    this->PINaddr=&PIND;    this->PORTaddr=&PORTD;} return;}

And this is what calls for it:

PINS RS;RS.usepin(&PORTC, 0);

Now this is how I thought it would work:

  1. Write e.g. "PINS RS;" to create an instance of class PINS; a new pin with the name RS.
  2. Write "RS.usepin(PORTB,0);" to configure RS pin to PORTB0 of MCU.
  3. Use RS.DDRaddr for DDR, RS.PINaddr for PIN and RS.PORTaddr for PORT register
  4. Use RS.pinnum for the pin number; eg: RS.DDRaddr|=(1<

When I try to build it in Atmel Studio I have the following error for every line like this: "this->DDRaddr=&DDRB;" The error says:

Error 1 invalid conversion from volatile uint8_t* to uint8_t*

It used to work before I made uint8_t* DDRaddr a class member. I can't understand what is the problem, i couldn't make a conclusion from similar – but yet not quite the same – questions.
Is there anyone who could have an idea of what is wrong with this specific code?

Best Solution

Apparently DDRB is of type volatile uint8_t, but you're trying to assign its address into a uint8_t*. That's not allowed - volatile follows the same rules as const in this regard.

If you intend to use the members like this, you'll have to declare them as pointers to volatile:

class PINS{public://ATTRIBUTESvolatile uint8_t* DDRaddr;volatile uint8_t* PORTaddr;volatile uint8_t* PINaddr;// ... rest as before