public inbox for gcc-help@gcc.gnu.org
 help / color / mirror / Atom feed
* How do I assign an attribute to a function
@ 2013-11-15 20:03 ballsystemlord
  2013-11-16  8:19 ` Ian Lance Taylor
  0 siblings, 1 reply; 3+ messages in thread
From: ballsystemlord @ 2013-11-15 20:03 UTC (permalink / raw)
  To: gcc-help

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?



--
View this message in context: http://gcc.1065356.n5.nabble.com/How-do-I-assign-an-attribute-to-a-function-tp985730.html
Sent from the gcc - Help mailing list archive at Nabble.com.

^ permalink raw reply	[flat|nested] 3+ messages in thread

* Re: How do I assign an attribute to a function
  2013-11-15 20:03 How do I assign an attribute to a function ballsystemlord
@ 2013-11-16  8:19 ` Ian Lance Taylor
  2013-11-20 17:43   ` ballsystemlord
  0 siblings, 1 reply; 3+ messages in thread
From: Ian Lance Taylor @ 2013-11-16  8:19 UTC (permalink / raw)
  To: ballsystemlord; +Cc: gcc-help

On Fri, Nov 15, 2013 at 12:03 PM, ballsystemlord <doark@mail.com> 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

^ permalink raw reply	[flat|nested] 3+ messages in thread

* Re: How do I assign an attribute to a function
  2013-11-16  8:19 ` Ian Lance Taylor
@ 2013-11-20 17:43   ` ballsystemlord
  0 siblings, 0 replies; 3+ messages in thread
From: ballsystemlord @ 2013-11-20 17:43 UTC (permalink / raw)
  To: gcc-help

Ian Lance Taylor-3 wrote
>>On Fri, Nov 15, 2013 at 12:03 PM, ballsystemlord &lt;

> doark@

> &gt; 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
>>

Ok, Thanks.



--
View this message in context: http://gcc.1065356.n5.nabble.com/How-do-I-assign-an-attribute-to-a-function-tp985730p987621.html
Sent from the gcc - Help mailing list archive at Nabble.com.

^ permalink raw reply	[flat|nested] 3+ messages in thread

end of thread, other threads:[~2013-11-20 17:41 UTC | newest]

Thread overview: 3+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2013-11-15 20:03 How do I assign an attribute to a function ballsystemlord
2013-11-16  8:19 ` Ian Lance Taylor
2013-11-20 17:43   ` ballsystemlord

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).