[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
Re: Is it safe to use ax_gcc_builtin to detect __builtin_offsetof?
From: |
Nick Bowler |
Subject: |
Re: Is it safe to use ax_gcc_builtin to detect __builtin_offsetof? |
Date: |
Sun, 25 Feb 2024 14:23:50 -0500 |
User-agent: |
Mozilla/5.0 (X11; Linux x86_64; rv:102.0) Gecko/20100101 Thunderbird/102.15.0 |
On 2024-02-25 02:28, Jeffrey Walton wrote:
> On Sun, Feb 25, 2024 at 2:09 AM Jeffrey Walton <noloader@gmail.com> wrote:
>> The page <https://www.gnu.org/software/autoconf-archive/ax_gcc_builtin.html>
>> does not list __builtin_offsetof in the list of documented builtins.
>> But the page says "Unsupported built-ins will be tested with an empty
>> parameter set and the result of the check might be wrong or
>> meaningless so use with care."
>>
>> Is it safe to use ax_gcc_builtin to detect __builtin_offsetof?
This is the Autoconf list. Despite the similar name, Autoconf Archive
is a separate project, and the author(s) of that macro (who would be the
people who can actually answer this question) might not be on this list.
Personally, if I really needed to probe the whether __builtin_offsetof
works then the Autoconf-provided AC_COMPUTE_INT macro should be more than
good enough to do this. Something like (untested):
AC_CACHE_CHECK([for __builtin_offsetof], [my_cv_builtin_offsetof],
[AC_COMPUTE_INT([testval],
[__builtin_offsetof(struct foo, b) == (char *)&bar.b - (char *)&bar],
[ struct foo { char a; int b; } bar;],
[testval=0])
AS_CASE([$testval],
[1], [my_cv_builtin_offsetof=yes],
[my_cv_builtin_offsetof=no])])
AS_CASE([$my_cv_builtin_offsetof],
[yes], [AC_DEFINE([HAVE___BUILTIN_OFFSETOF], [1],
[Define to 1 if __builtin_offsetof works])])
Test on both a system that supports __builtin_offsetof and one that
doesn't, this will probably be good enough unless you have specific
knowledge of systems that are buggy or different in some way.
Hope that helps,
Nick