__builtin_constant_p for trivial operations

Marc Glisse marc.glisse at inria.fr
Sun Feb 20 21:43:01 CET 2011


On Sun, 20 Feb 2011, Torbjorn Granlund wrote:

> I don't understand how this could work.
>
> It seems that you are suggesting to apply __builtin_constant_p to an
> argument of an inline function.  Alas, I don't think that would ever
> evaluate to 1, since __builtin_constant_p is expanded quite early.

It is expanded late enough to work for inline functions.

#include <stdio.h>
static inline void f(int*a,int*b){
 	printf("%d\n",__builtin_constant_p(a==b));
}
#define g(a,b) \
 	printf("%d\n",__builtin_constant_p((a)==(b)));
int main(){
 	int p=42;
 	f(&p,&p);
 	g(&p,&p);
 	return 0;
}

With gcc-4.4, without optimization it prints 0 and 1, but at -O1 it prints 
1 and 1.

-- 
Marc Glisse


More information about the gmp-discuss mailing list