Re: Is it safe to use ax_gcc_builtin to detect __builtin_offsetof?

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

 



On 2024-02-25 02:28, Jeffrey Walton wrote:
> On Sun, Feb 25, 2024 at 2:09 AM Jeffrey Walton <noloader@xxxxxxxxx> 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




[Index of Archives]     [GCC Help]     [Kernel Discussion]     [RPM Discussion]     [Red Hat Development]     [Yosemite News]     [Linux USB]     [Samba]

  Powered by Linux