Beefy Boxes and Bandwidth Generously Provided by pair Networks
go ahead... be a heretic

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 all is quiet...

How do I use this? | Other CB clients
Other Users?
Others chilling in the Monastery: (7)
As of 2018-07-19 16:00 GMT
Find Nodes?
    Voting Booth?
    It has been suggested to rename Perl 6 in order to boost its marketing potential. Which name would you prefer?

    Results (411 votes). Check out past polls.