Hi,

I've been pondering the addition of a new "pgm_read_ptr()" macro to 
<avr/pgmspace.h> to fill a gap (in my eyes) in the current API. Currently, to 
read out pointers stored in PROGMEM space, one has to use pgm_read_word() and 
cast the result to the desired pointer. This is bad (IMHO) as it requires 
specific knowledge of the exact pointer width on the AVRs, which could in 
theory change, and it makes the code a little harder to read.

I'm proposing a simple extra macro be added:

#define pgm_read_ptr( x )    (void*)pgm_read_word( x )

Which would hide this from the user, so they do not have to use the more 
ambiguous macros when dealing with progmem pointers. This would also be helpful 
as it is implicitly typecast to the correct pointer type when used as a 
initialiser, like:

char* FlashPtr = pgm_read_ptr(&FlashPointer);

Without user intervention. Thoughts anyone?

Cheers!
- Dean
_______________________________________________
AVR-libc-dev mailing list
[email protected]
http://lists.nongnu.org/mailman/listinfo/avr-libc-dev

Reply via email to