autoconf
[Top][All Lists]
Advanced

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

Re: probing for compiler attributes?


From: Benoit SIGOURE
Subject: Re: probing for compiler attributes?
Date: Thu, 9 Aug 2007 10:02:00 +0200

On Aug 9, 2007, at 3:29 AM, Joshua Hoblitt wrote:

On Tue, Aug 07, 2007 at 08:43:54PM -0400, John W. Eaton wrote:
Ugh.  Don't do it like that.  Instead, write something like

  your-config-header.h:
  --------------------
  #ifdef __GNUC__
  #define ATTR_MALLOC __attribute__((malloc))
  #else
  #define ATTR_MALLOC
  #endif

and then in your code, just use

  #include "your-config-header.h"
  ...
  void *myfunc (char *myvar) ATTR_MALLOC;

The more I think about it the more I think this is a bad idea for
library code.  It certainly makes the code more tidy but doesn't this
end up screwing any application that tries to link against your code? I
don't ever install config.h.


That's true although I've already seen some packages doing this (prefixing all the #defines of config.h with the name of the package, rename the file itself and install it). Now I *think* (wild guess :D) that it won't screw anything up at least with the malloc __attribute__ because this attribute does not change anything WRT the ABI, it merely helps the compiler in doing its alias analysis job (which can lead to better optimizations at call site).

http://gcc.gnu.org/onlinedocs/gcc-4.2.1/gcc/Function- Attributes.html#index-g_t_0040code_007bmalloc_007d-attribute-1869 "The malloc attribute is used to tell the compiler that a function may be treated as if any non-NULL pointer it returns cannot alias any other pointer valid when the function returns. This will often improve optimization." [...]

So, really, I hardly see how this can harm. Some other attributes however would be more problematic. For instance, I guess that if you declare a function __attribute__ ((always_inline)), the symbol for that function won't exist in the library compiled, and if someone uses a compiler that doesn't support this attribute tries to link to your library, the linker may complain that the symbol could not be found.

Cheers,

--
Benoit Sigoure aka Tsuna
EPITA Research and Development Laboratory


Attachment: PGP.sig
Description: This is a digitally signed message part


reply via email to

[Prev in Thread] Current Thread [Next in Thread]