Skip to content

Commit

Permalink
compat: make gcc bswap an inline function
Browse files Browse the repository at this point in the history
Without this change, gcc -pedantic warns:

 cache.h: In function 'ce_to_dtype':
 cache.h:270:21: warning: ISO C forbids braced-groups within expressions [-pedantic]

An inline function is more readable anyway.

Signed-off-by: Jonathan Nieder <jrnieder@gmail.com>
Signed-off-by: Junio C Hamano <gitster@pobox.com>
  • Loading branch information
Jonathan Nieder authored and Junio C Hamano committed Mar 16, 2011
1 parent c9b6782 commit c6c8d0b
Showing 1 changed file with 10 additions and 8 deletions.
18 changes: 10 additions & 8 deletions compat/bswap.h
Original file line number Diff line number Diff line change
Expand Up @@ -21,14 +21,16 @@ static inline uint32_t default_swab32(uint32_t val)

#if defined(__GNUC__) && (defined(__i386__) || defined(__x86_64__))

#define bswap32(x) ({ \
uint32_t __res; \
if (__builtin_constant_p(x)) { \
__res = default_swab32(x); \
} else { \
__asm__("bswap %0" : "=r" (__res) : "0" ((uint32_t)(x))); \
} \
__res; })
#define bswap32 git_bswap32
static inline uint32_t git_bswap32(uint32_t x)
{
uint32_t result;
if (__builtin_constant_p(x))
result = default_swab32(x);
else
__asm__("bswap %0" : "=r" (result) : "0" (x));
return result;
}

#elif defined(_MSC_VER) && (defined(_M_IX86) || defined(_M_X64))

Expand Down

0 comments on commit c6c8d0b

Please sign in to comment.