Re: [PATCH 2/8] compat: make gcc bswap an inline function
- From
Jonathan Nieder <jrnieder@gmail.com>
- Date
- Mar 16, 2011, 09:31 UTC
- Message-ID
- <20110316093108.GB7886@elie>
- In-Reply-To
- <4D808126.8070706@viscovery.net>
Johannes Sixt wrote:
> Am 3/16/2011 8:00, schrieb Jonathan Nieder:
Show 7 quoted lines
>> +static inline uint32_t git_bswap32(uint32_t x)
>> +{
>> + uint32_t result;
>> + if (__builtin_constant_p(x))
>
> Can this predicate ever be true? Isn't it false even if the function is
> inlined?It's true if x is a constant.
$ cat test.c #if 0 gcc -Wall -W -O -o tryit "$0" exec ./tryit #else #include <stdio.h> #include <stdint.h>
#ifdef __GNUC__
static inline int constant(uint32_t x)
{
return __builtin_constant_p(x);
}
#else
static inline int constant(uint32_t x) { return 0; }
#endifint main(void)
{
printf("%d\n", constant(3 + 5));
return 0;
}
#endif
$ ./test.c
1