"lvalue required as unary '&' operand" error when adding "#include <SD.h>"

So was running fine until I added
#include <SD.h>
now returns error
lvalue required as unary '&' operand
pointing towards
#include <Diablo_Const4D.h> line 977 #define PINK 0xFE19.

What is causing this error? All I'm trying to do is add an SD card to an existing working program. SD code works fine on its own but when added to existing code the error is created.

Code attached, thanks in advance.

Simon

help.txt (13.2 KB)

Instead of paraphrasing the error, could you please copy and paste it here, as text?

Please include the entire error message. It is easy to do. There is a button (lower right of the IDE window) called "copy error message". Copy the error and paste into a post in code tags. Paraphrasing the error message leaves out important information.

Of course, sorry.

Arduino: 1.8.12 (Windows 10), Board: "Arduino Mega or Mega 2560, ATmega2560 (Mega 2560)"

In file included from C:\Program Files (x86)\Arduino\libraries\Diablo_Serial_4DLib/Diablo_Serial_4DLib.h:15:0,

from C:\Users\44784\Documents\Arduino\SD_Mega_Inergen_Detector_with_print__timestamp_and_clock\SD_Mega_Inergen_Detector_with_print__timestamp_and_clock.ino:6:

Diablo_Const4D.h:977:33: error: lvalue required as unary '&' operand

#define PINK 0xFE19

^

C:\Program Files (x86)\Arduino\libraries\SD\src/utility/Sd2PinMap.h:140:12: note: in expansion of macro 'PINK'

{&DDRK, &PINK, &PORTK, 0}, // K0 62

^~~~

Diablo_Const4D.h:977:33: error: lvalue required as unary '&' operand

#define PINK 0xFE19

^

C:\Program Files (x86)\Arduino\libraries\SD\src/utility/Sd2PinMap.h:141:12: note: in expansion of macro 'PINK'

{&DDRK, &PINK, &PORTK, 1}, // K1 63

^~~~

Diablo_Const4D.h:977:33: error: lvalue required as unary '&' operand

#define PINK 0xFE19

^

C:\Program Files (x86)\Arduino\libraries\SD\src/utility/Sd2PinMap.h:142:12: note: in expansion of macro 'PINK'

{&DDRK, &PINK, &PORTK, 2}, // K2 64

^~~~

Diablo_Const4D.h:977:33: error: lvalue required as unary '&' operand

#define PINK 0xFE19

^

C:\Program Files (x86)\Arduino\libraries\SD\src/utility/Sd2PinMap.h:143:12: note: in expansion of macro 'PINK'

{&DDRK, &PINK, &PORTK, 3}, // K3 65

^~~~

Diablo_Const4D.h:977:33: error: lvalue required as unary '&' operand

#define PINK 0xFE19

^

C:\Program Files (x86)\Arduino\libraries\SD\src/utility/Sd2PinMap.h:144:12: note: in expansion of macro 'PINK'

{&DDRK, &PINK, &PORTK, 4}, // K4 66

^~~~

Diablo_Const4D.h:977:33: error: lvalue required as unary '&' operand

#define PINK 0xFE19

^

C:\Program Files (x86)\Arduino\libraries\SD\src/utility/Sd2PinMap.h:145:12: note: in expansion of macro 'PINK'

{&DDRK, &PINK, &PORTK, 5}, // K5 67

^~~~

Diablo_Const4D.h:977:33: error: lvalue required as unary '&' operand

#define PINK 0xFE19

^

C:\Program Files (x86)\Arduino\libraries\SD\src/utility/Sd2PinMap.h:146:12: note: in expansion of macro 'PINK'

{&DDRK, &PINK, &PORTK, 6}, // K6 68

^~~~

Diablo_Const4D.h:977:33: error: lvalue required as unary '&' operand

#define PINK 0xFE19

^

C:\Program Files (x86)\Arduino\libraries\SD\src/utility/Sd2PinMap.h:147:12: note: in expansion of macro 'PINK'

{&DDRK, &PINK, &PORTK, 7} // K7 69

^~~~

C:\Users\44784\Documents\Arduino\SD_Mega_Inergen_Detector_with_print__timestamp_and_clock\SD_Mega_Inergen_Detector_with_print__timestamp_and_clock.ino: In function 'void loop()':

SD_Mega_Inergen_Detector_with_print__timestamp_and_clock:109:24: error: expected ')' before 'Test'

myFile.print("#" Test Switch opened at "");

^~~~

exit status 1
lvalue required as unary '&' operand

This report would have more information with
"Show verbose output during compilation"
option enabled in File -> Preferences.

{&DDRK, &PINK, &PORTK, 1}, That's just stupid, isn't it?
How can you take the address of a numeric literal?

Thanks but sorry I don't understand. What is the fix?

"PINK" is defined as an integer literal, which is a prvalue. You cannot take the address of a (p)rvalue, because it doesn't have an address, it's a temporary that doesn't necessarily exist in RAM.
You can only take addresses of lvalues, which is what the compiler is telling you.

The macro PINK conflicts with the builtin register name PINK, which is the register for GPIO input values of IO bank K.

"PINK" (the color) shouldn't be defined as a macro. The author of the library it's part of should have used constexpr or const variables, and it should probably have been in a namespace to avoid conflicts like this.
You should report this to the library's maintainer.

Pieter

I see. But why pink and not the others? (sample but by no means all, below)

#define GOLD 0xFEA0
#define GOLDENROD 0xDD24
#define GRAY 0x8410
#define GREEN 0x0400
#define GREENYELLOW 0xAFE5
#define HONEYDEW 0xF7FE
#define HOTPINK 0xFB56
#define INDIANRED 0xCAEB
#define INDIGO 0x4810
#define IVORY 0xFFFE
#define KHAKI 0xF731
#define LAVENDER 0xE73F
#define LAVENDERBLUSH 0xFF9E
#define LAWNGREEN 0x7FE0
#define LEMONCHIFFON 0xFFD9
#define LIGHTBLUE 0xAEDC
#define LIGHTCORAL 0xF410
#define LIGHTCYAN 0xE7FF
#define LIGHTGOLD 0xFFDA
#define LIGHTGREEN 0x9772
#define LIGHTGREY 0xD69A
#define LIGHTPINK 0xFDB8
#define LIGHTSALMON 0xFD0F
#define LIGHTSEAGREEN 0x2595
#define LIGHTSKYBLUE 0x867F
#define LIGHTSLATEGRAY 0x7453
#define LIGHTSTEELBLUE 0xB63B
#define LIGHTYELLOW 0xFFFC
#define LIME 0x07E0
#define LIMEGREEN 0x3666
#define LINEN 0xFF9C
#define MAGENTA 0xF81F
#define MAROON 0x8000
#define MEDIUMAQUAMARINE 0x6675
#define MEDIUMBLUE 0x0019
#define MEDIUMORCHID 0xBABA
#define MEDIUMPURPLE 0x939B
#define MEDIUMSEAGREEN 0x3D8E
#define MEDIUMSLATEBLUE 0x7B5D
#define MEDIUMSPRINGGREEN 0x07D3
#define MEDIUMTURQUOISE 0x4E99

And it worked fine until I added the SD.h library.

Only PINK causes the error because the other color names don't conflict with PIN registers.
And before you included the SD.h library, the PIN register PINK wasn't used in your sketch.

dorissimus:
And it worked fine until I added the SD.h library.

But none of those other colours are register names

cool, I'm learning here thank you. So how to rectify? Can I rename or delete the pink?

Comment it out.
All it takes is a couple of slashes

dorissimus:
cool, I'm learning here thank you. So how to rectify? Can I rename or delete the pink?

It might work if you include the SD library before whatever library is defining PINK.

I tried it with pink removed, it then errored on plum ::slight_smile:

But moving the SD library above the library declaring pink did work, now compiling error free.

Thank you all, a great result ;D

It's safer to rename it.