strlen() and constant folding
Bryan Christ
bryan.christ@gmail.com
Tue Jun 30 16:38:00 GMT 2009
Interesting. Is this documented somewhere? Is it reliable
cross-platform? What if...
int poo(void)
{
const char *test="test";
const char *foo;
foo=test;
return strlen(foo);
}
On Tue, Jun 30, 2009 at 4:25 AM, Andrew Haley<aph@redhat.com> wrote:
> Bryan Christ wrote:
>> Is there some way to tell gcc to behave in a way that would be
>> analogous to constant folding when dealing with strlen() calls where
>> the target is const char* type? If there is a macro or different
>> directive that would accomplish the same, that would be okay for my
>> purposes.
>
> Works for me:
>
> int poo(void)
> {
> return strlen("test");
> }
>
> poo:
> movl $4, %eax
> ret
>
> Andrew.
>
--
Bryan
<><
More information about the Gcc-help
mailing list