strlen() and constant folding

Andrew Haley aph@redhat.com
Tue Jun 30 09:25:00 GMT 2009


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.



More information about the Gcc-help mailing list