[Top][All Lists]

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

[avr-libc-dev] New pgm_read_ptr() macro?

From: Dean Camera
Subject: [avr-libc-dev] New pgm_read_ptr() macro?
Date: Tue, 1 Jun 2010 21:34:25 +1000


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?

- Dean

reply via email to

[Prev in Thread] Current Thread [Next in Thread]