Welcome to ShenZhenJia Knowledge Sharing Community for programmer and developer-Open, Learning and Share
menu search
person
Welcome To Ask or Share your Answers For Others

Categories

UPDATED PROGRESS

I am sorry I forgot to specify this question as an Arduino question. I just assumed that it's a preprocessor problem which is kind of independent of what platform this is being executed on.

I am using Arduino-Make and I am trying to pass in USERNAME and PASSWORD

BOARD_TAG    = mega2560
CPPFLAGS     = -DUSERNAME="$(USERNAME)" -DPASSWORD="$(PASSWORD)"
include $(ARDMK_DIR)/Arduino.mk

Command line:

make USERNAME="HELLO" PASSWORD="WORLD"

Code:

void setup() {
  Serial.begin(9600);

  String auth_raw2(USERNAME : PASSWORD);
  Serial.println(auth_raw2);
}


void loop() {}

I am getting this error:

macro.ino:10:29: error: found ‘:’ in nested-name-specifier, expected ‘::’
macro.ino:10:20: error: ‘HELLO’ has not been declared
See Question&Answers more detail:os

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
thumb_up_alt 0 like thumb_down_alt 0 dislike
998 views
Welcome To Ask or Share your Answers For Others

1 Answer

What you want is

String auth_raw( USERNAME ":" PASSWORD );

That will do the proper literal string concatenation you're looking for. The compiler will run adjacent string literals together into a single string. So if you have

char a[] = "The " "quick" " brown " "fox";

it treats it the same as if you wrote

char a[] = "The quick brown fox";

I'm not sure about putting " around the values provided on the command line to make.


与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
thumb_up_alt 0 like thumb_down_alt 0 dislike
Welcome to ShenZhenJia Knowledge Sharing Community for programmer and developer-Open, Learning and Share
...