Ticket #151 (assigned enhancement)

Opened 20 months ago

Last modified 3 weeks ago

Use function attributes to mark functions as "const", "pure", and "nothrow"

Reported by: olly Owned by: olly
Priority: normal Milestone: 1.1.1
Component: Other Version: SVN trunk
Severity: minor Keywords:
Cc: Blocked By:
Operating System: All Blocking:

Description (last modified by richard) (diff)

GCC allows functions to be annotate with attribute((const)) if they "do not examine any values except their arguments, and have no effects except the return value", which allows the compiler to use CSE to eliminate calls to them with identical arguments. This would probably be very useful for Xapian::Unicode::get_category() for example.

URL: http://gcc.gnu.org/onlinedocs/gcc-4.1.2/gcc/Function-Attributes.html#Function-Attributes

Change History

Changed 20 months ago by olly

  • status changed from new to assigned
  • blocking set to 120
  • summary changed from Use function attributes to mark functions as "const", "pure", and "nothrow".pure and const functions to Use function attributes to mark functions as "const", "pure", and "nothrow"

Oops, finger trouble...

attribute((const)) is available for (at least) GCC 2.95 onwards, which is all the versions we support.

There's also attribute((pure)) which is like const, but the function may also examine global memory, perhaps via pointer (or presumably reference) parameters. This is available from GCC 2.96 onwards.

MSVC doesn't seem to have equivalents for either of these.

Both GCC and MSVC support nothrow (as attribute and declspec respectively) to indicate a function doesn't throw exceptions. ISO C++ has "throw()" - not sure if this is the same or subtely different though.

GCC also allows functions to be marked listing pointer parameters which can't be NULL, which may be worth considering.

Marking this for consideration for 1.0.X.

Changed 20 months ago by trac

  • platform set to All

Changed 9 months ago by richard

  • description modified (diff)
  • milestone set to 1.1

Changed 9 months ago by richard

  • blocking deleted

(In #120) Remove the unfixed dependencies so we can close this bug - they're all marked for the 1.1.0 milestone.

Changed 3 weeks ago by olly

  • milestone changed from 1.1.0 to 1.1.1

Doing this to internal functions wouldn't affect the ABI and to external functions wouldn't affect the API so bumping to 1.1.1.

Note: See TracTickets for help on using tickets.