Beefy Boxes and Bandwidth Generously Provided by pair Networks
The stupid question is the question not asked

Re^4: I'm trying to consolidate my functions into subroutines

by Anonymous Monk
on May 17, 2017 at 17:09 UTC ( #1190479=note: print w/replies, xml ) Need Help??

in reply to Re^3: I'm trying to consolidate my functions into subroutines
in thread I'm trying to consolidate my functions into subroutines

As AnomalousMonk wrote, such function attributes are GNU C extensions. But they can be considered de facto standard features on many platforms. Excerpt from gcc info's:

  • const. Many functions do not examine any values except their arguments, and have no effects except the return value. Basically this is just slightly more strict class than the `pure' attribute below, since function is not allowed to read global memory....
  • pure. Many functions have no effects except the return value and their return value depends only on the parameters and/or global variables. Such a function can be subject to common subexpression elimination and loop optimization just as an arithmetic operator would be. These functions should be declared with the attribute `pure'. For example,
    int square (int) __attribute__ ((pure));
    says that the hypothetical function `square' is safe to call fewer times than the program says....
Note that in many cases, the compiler can discover those attributes on its own (and even offer suggestions to the programmer via warnings.)

ps. Take care not to confuse type qualifier const with attribute((const))

Replies are listed 'Best First'.
Re^5: I'm trying to consolidate my functions into subroutines
by afoken (Abbot) on May 17, 2017 at 19:51 UTC

    gcc has more than just function attributes. Variables, types, labels, enums, and statements also can have attributes. They all share a common syntax, choosen in a way that the programmer can use a preprocessor macro to hide gcc attributes from a non-gcc compiler.


    Today I will gladly share my knowledge and experience, for there are no sweeter words than "I told you so". ;-)

Log In?

What's my password?
Create A New User
Node Status?
node history
Node Type: note [id://1190479]
and the web crawler heard nothing...

How do I use this? | Other CB clients
Other Users?
Others having an uproarious good time at the Monastery: (8)
As of 2018-10-22 16:33 GMT
Find Nodes?
    Voting Booth?
    When I need money for a bigger acquisition, I usually ...

    Results (121 votes). Check out past polls.

    • (Sep 10, 2018 at 22:53 UTC) Welcome new users!