avr-gcc-list
[Top][All Lists]
Advanced

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

[avr-gcc-list] __attr_const__ attribute and strlen_P() and friends


From: Ned Konz
Subject: [avr-gcc-list] __attr_const__ attribute and strlen_P() and friends
Date: Tue, 7 Mar 2006 20:37:09 -0800

I'm sure this is a stupid question, but I was wondering...

I noticed that in the avr-libc header <pgmspace.h> that there are declarations including:

extern size_t strlen_P(PGM_P) __ATTR_CONST__; /* program memory can't change */ extern size_t strnlen_P(PGM_P, size_t) __ATTR_CONST__; /* program memory can't change */

where __ATTR_CONST__ is defined as __attribute__((__const__))

Now, it says in the GCC 4.0 manual about function attributes in the section about "const" that:

--
const
Many functions do not examine any values except their arguments, and have no effects except the return value. Basically this is just slightly more strict class than the pure attribute below, since function is not allowed to read global memory.

Note that a function that has pointer arguments and examines the data pointed to must not be declared const. Likewise, a function that calls a non-const function usually must not be const. It does not make sense for a const function to return void.
--

Of course, strlen_P() *does* have pointer arguments, and *does* examine the data pointed to (though only in a read-only way).
Is it a problem that it is declared const, considering the above?

And if I was using the self-programming flash capabilities of the AVR would this be a problem?

--
Ned Konz
address@hidden






reply via email to

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