[Icc-avr] RFC: __flash vs. const

David Brown david_brown at hotpop.com
Tue Nov 6 00:16:48 PST 2007


Richard wrote:
> For the upcoming release that supports __flash, it turns out to be more 
> difficult to add a backward compatibility than I thought. The problem is 
> mainly the library functions. For example, properly, the strcpy is 
> declared as
> 
> char *strcpy(char *src, const char *dst);
> 

I hope you meant:

char *strcpy(char *dst, const char *src);


> The const qualifier of the "dst" argument will cause trouble with the 
> new release if there is a backward compatibility switch on. The best 
> solution is probably something like declaring it as
> 
> char *strcpy(char *, _CONST char *)
> 
> where _CONST is #define'd as nothing if the backward compat switch is 
> on, and const otherwise.
> 
> Or we will bite the bullet and request all users henceforth only use 
> __flash to mean flash space. This would of course make it difficult to 
> have compatible sources for multiple releases.
> 
> Comments? Suggestions?
> 

I'd go with your _CONST plan (although such compiler-defined macros 
should perhaps have two leading underscores, like __flash?).  It's clear 
what it is doing, and gives people the choice.

When compiling in backwards compatibility mode, perhaps __flash should 
be a macro expanding to "const" ?  This would, I think, give a smoother 
transition, as "__flash" will then give the expected effect in both modes.

I'd also have *two* switches to control the mode.  You would have one
to enable the new __flash mode, and one to enable the old const mode. 
If neither switch is used, the code will compile in the old const mode 
but give a warning that an explicit switch should be used.  In later 
versions, change the warning to an error.  That would, I think, minimise 
the possibility of accidents.

mvh.,

David



More information about the Icc-avr mailing list