Passing formatted FLASH-string to a function

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

With AS 6 it seems that the usage of prog_char has changed, so thias code does not work anymore.

void text(PROGMEM *fmt, ...)
{
	uint8_t *buffer=malloc(120);
	
	va_list vl;
	va_start(vl, fmt);
	snprintf_P((char *)buffer,120,fmt,vl);
	//vfprintf_P(LCD, fmt, vl);
	va_end(vl);
	
	sim_SendDiagnosticString(buffer);
	free(buffer);
}	

The Goal is to pass a formatted string with arguments (like in printf) to a function where the decoded string is placed in a buffer for further porcessing.

But prog_char does not work anymore and I don't understand the postings on how to Change the code.

I program like a man:
COPY CON: > firmware.hex

  • 1
  • 2
  • 3
  • 4
  • 5
Total votes: 0
void text(PGM_P fmt, ...) 

PGM_P is only a euphemism for const char PROGMEM *

Untested. But your PROGMEM *fmt is clearly pants!

David.

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

When you actually pass the pointer it could just as easily be a RAM, flash or EEPROM pointer. It's only when you dereference it and how you do that which determines if it is actually a flash pointer.

BTW if using 6.1Beta you probably want to explore __flash as then you don't need pgm_read*() functions to access the data.

The latest user manual :

www.nongnu.org/avr-libc/user-man...

explains what's happened to prog_char.

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

It seems to work now. Thank you for your help.

I program like a man:
COPY CON: > firmware.hex