Re: How do I assign an attribute to a function

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

 



On Fri, Nov 15, 2013 at 12:03 PM, ballsystemlord <doark@xxxxxxxx> wrote:
> I'm using C and I decided to read the whole gcc info manual on the subject.
> How do I apply an __attribute__ to the function as apposed to what it
> returns?
> Yes, I've read the docs and am looking for examples.
> I want to apply the cold __attribute__ to all the perror statements in my
> program, the perror function is declared in the GNU C library so how do I
> change it without effecting every other program that's compiled against the
> GNU C library?

In general, you can't.

In GCC 4.8 or later you can  use the cold attribute on a label.  Then
you can turn your calls to perror into a goto to that label.

Otherwise you can use __builtin_expect, as in

  if (__builtin_expect (ok, true))
    {
      // Normal case.
    }
  else
    perror ("error");

Ian




[Index of Archives]     [Linux C Programming]     [Linux Kernel]     [eCos]     [Fedora Development]     [Fedora Announce]     [Autoconf]     [The DWARVES Debugging Tools]     [Yosemite Campsites]     [Yosemite News]     [Linux GCC]

  Powered by Linux