Go Down

Topic: error: invalid conversion from 'const char*' to 'char' [-fpermissive] (Read 43023 times) previous topic - next topic

rremm2000

I've made a few global vars / constants to handle serial port input, ran into this error

junk.ino: In function 'void loop()':
junk.ino:35:13: error: invalid conversion from 'const char*' to 'char' [-fpermissive]
Error compiling.


I didn't declare this as a const char, just char so I could put new char data into it but, this error is got me confused?

Code: [Select]

bool serControl       = false;
int serIntIn          = 0;
char serCharIn     ="";
String serStringIn    = "";
const int SER_RET_INT       = 1;
const int SER_RET_CHAR      = 2;
const int SER_RET_STRING    = 3;

void setup()
{
 
Serial.begin(19200); // opens serial port, sets data rate to 9600 bps
  //attachInterrupt(1, intCnt, RISING  ); // syntax attachInterrupt(interrupt, ISR, mode)
  //interrupts();
  //tickEvent = t.every(2000, intCnt); //doFreeRun is controlled by timer
 
   
 
}

void loop() {
serIntIn    = 0;
serCharIn   = "";
serStringIn = "";



}

-------------
It's a fool who looks for anything other than blood in the chambers of the human heart, for both passion and logic emanate from the human mind.

larryd

Using "const" prevents you from changing the variable in code.

Remove const from variables you change.


Edit, my mistake


.
No technical PMs.
If you are asked a question, please respond with an answer.
If you are asked for more information, please supply it.
If you need clarification, ask for help.

rremm2000

Hopefully the "edit my mistake" was you realized that I don't have const before the error because the error is on line 35 which is
Code: [Select]
serCharIn   = "";

it's declared as a char not a const char?

If I misunderstood your post then please clarify
-------------
It's a fool who looks for anything other than blood in the chambers of the human heart, for both passion and logic emanate from the human mind.

larryd

No technical PMs.
If you are asked a question, please respond with an answer.
If you are asked for more information, please supply it.
If you need clarification, ask for help.

larryd

You need '  ' rather than "  "


Code: [Select]

bool serControl       = false;
int serIntIn          = 0;
char serCharIn        = ' ';  //<<<<<<< use ' apostrophes
String serStringIn    = "";
const int SER_RET_INT       = 1;
const int SER_RET_CHAR      = 2;
const int SER_RET_STRING    = 3;

void setup()
{
  Serial.begin(19200); // opens serial port, sets data rate to 9600 bps
  //attachInterrupt(1, intCnt, RISING  ); // syntax attachInterrupt(interrupt, ISR, mode)
  //interrupts();
  //tickEvent = t.every(2000, intCnt); //doFreeRun is controlled by timer
}
void loop() {
  serIntIn    = 0;
  serCharIn   = ''; //<<<<<<< use ' apostrophes
  serStringIn = "";
}


No technical PMs.
If you are asked a question, please respond with an answer.
If you are asked for more information, please supply it.
If you need clarification, ask for help.

rremm2000

Can I ask why I would need '' verses "" for a char verses a string?

Actually I tried it with single quotes and got the same error

If I just change the declaration I get.....

Build options changed, rebuilding all
junk.ino:15:25: error: empty character constant
junk.ino: In function 'void loop()':
junk.ino:35:13: error: invalid conversion from 'const char*' to 'char' [-fpermissive]
Error compiling.

If I change the initialization
junk.ino:35:15: error: empty character constant
junk.ino:15:25: error: invalid conversion from 'const char*' to 'char' [-fpermissive]
Error compiling.

and if I change both I still have...
junk.ino:15:25: error: empty character constant
junk.ino:35:15: error: empty character constant
Error compiling.
-------------
It's a fool who looks for anything other than blood in the chambers of the human heart, for both passion and logic emanate from the human mind.

larryd

'  char, is a single character variable like 'C' or '$'.
" String, is a string of characters like "now is the time for all good men to come to the aid of the party"
No technical PMs.
If you are asked a question, please respond with an answer.
If you are asked for more information, please supply it.
If you need clarification, ask for help.

larryd

No technical PMs.
If you are asked a question, please respond with an answer.
If you are asked for more information, please supply it.
If you need clarification, ask for help.

michinyon

You didn't get "the same error",  at all.


You tried to define a char variable with

char serCharIn = ''  ;   

which is invalid.   That is two single quotes there,    and there has to be a char constant between them.  One char.   Not zero chars.  That's what "junk.ino:35:15: error: empty character constant" says.

A char is one char

A const char*  is a pointer to the beginning of an array of chars  (  which might be an array consisting of one element ).


itsacoolaccount

You need '  ' rather than "  "


Code: [Select]

bool serControl       = false;
int serIntIn          = 0;
char serCharIn        = ' ';  //<<<<<<< use ' apostrophes
String serStringIn    = "";
const int SER_RET_INT       = 1;
const int SER_RET_CHAR      = 2;
const int SER_RET_STRING    = 3;

void setup()
{
  Serial.begin(19200); // opens serial port, sets data rate to 9600 bps
  //attachInterrupt(1, intCnt, RISING  ); // syntax attachInterrupt(interrupt, ISR, mode)
  //interrupts();
  //tickEvent = t.every(2000, intCnt); //doFreeRun is controlled by timer
}
void loop() {
  serIntIn    = 0;
  serCharIn   = ''; //<<<<<<< use ' apostrophes
  serStringIn = "";
}




This is true, I had the same issue. Doing that fixed it for my code.

Go Up