strlen() and constant folding

Andrew Haley aph@redhat.com
Tue Jun 30 16:46:00 GMT 2009


Bryan Christ wrote:
> Interesting.  Is this documented somewhere?

I doubt it.  Most optimizations aren't specially documented.

> Is it reliable cross-platform?

Yes.

> What if...
> 
> int poo(void)
> {
>    const char *test="test";
>    const char *foo;
> 
>    foo=test;
> 
>    return strlen(foo);
> }

poo():
	movl	$4, %eax
	ret

Andrew.



More information about the Gcc-help mailing list