why does this give a warnings

Go To Last Post
5 posts / 0 new
Author
Message
#1
  • 1
  • 2
  • 3
  • 4
  • 5
Total votes: 0

This code works fine but give 3 warnings why? 

it say assignment from incompatible pointer type

 

and which typecast to use or type of pointer to use (I know that this code use extra RAM, but I just want to get rid of the warnings at the moment). 

  char *ptr;
  ptr=NULL;
  if (i==0)
    ptr=&("Ready"); //at boot
  if (i==7)
    ptr=&("Ready test2"); //this is normal ready
  if (i==6)
    ptr=&("Run");
  if(ptr){
    while (*ptr){
      x+=LCDprintchar_big(x,y,*ptr++);
    }

 

This topic has a solution.
Last Edited: Tue. Dec 8, 2015 - 03:23 PM
This reply has been marked as the solution. 
  • 1
  • 2
  • 3
  • 4
  • 5
Total votes: 0

A string litteral is already an address.  No need for the &:

  ptr = NULL;

  if (i == 0)
    ptr = "Ready";                   //at boot
  if (i == 7)
    ptr = "Ready test2";             //this is normal ready
  if (i == 6)
    ptr = "Run";
  if (ptr) {
    while (*ptr) {
      x += LCDprintchar_big(x,y,*ptr++);
    }
  }

 

"Experience is what enables you to recognise a mistake the second time you make it."

"Good judgement comes from experience.  Experience comes from bad judgement."

"Wisdom is always wont to arrive late, and to be a little approximate on first possession."

"When you hear hoofbeats, think horses, not unicorns."

"Fast.  Cheap.  Good.  Pick two."

"We see a lot of arses on handlebars around here." - [J Ekdahl]

 

Last Edited: Tue. Dec 8, 2015 - 03:02 PM
  • 1
  • 2
  • 3
  • 4
  • 5
Total votes: 0

Not a criticism, but I generally shy away from anonymous strings in my AVR8 work.  Mostly historical, I guess -- the toolchains have matured with respect to handling AVR8 address spaces.

 

Now, I can only speculate on your toolchain of choice (though I have a good guess).  ptr is SRAM pointer, right?  While the code fragment is straightforward, with some kind of a full menu system aren't you going to strain SRAM resources with a lot of these anonymous strings?

 

For my full menu systems in AVR8 apps, I first create named strings that go into flash.  Often, I'll have a table of pointers to these strings that is then indexed when in the menu system.  Indeed that may not be the very smallest or very fastest.

 

If fixed-length strings (which I often have when building editing/monitor "panels" on character LCD displays) I often skip the separate table:

 


flash	char*	flash		flash_input_names[16] =
{
"Acid Sup  ",
"Acid Ret  ",
"Caus Sup  ",
"Caus Ret  ",
"Rinse Sup ",
"Reuse Sup ",
"Air Blow  ",
"Sanitizer ",
"Reuse Ret ",
"Reuse Fil ",
"CausB Sup ",
"CausB Ret ",
"Tank Wash ",
"Recirc    ",
"Egg Wash  ",
"Enable    "
};

...

memcpyf (&line3[10], flash_input_names[looper], 10);

 

You can put lipstick on a pig, but it is still a pig.

I've never met a pig I didn't like, as long as you have some salt and pepper.

  • 1
  • 2
  • 3
  • 4
  • 5
Total votes: 0

thanks.

 

 

  • 1
  • 2
  • 3
  • 4
  • 5
Total votes: 0

I know that was why I wrote the comment at the end of #1