[Xapian-tickets] [Xapian] #151: Use function attributes to mark functions as "const" or "pure" (was: Use function attributes to mark functions as "const", "pure", and "nothrow")
Xapian
nobody at xapian.org
Wed Mar 3 03:23:00 GMT 2010
#151: Use function attributes to mark functions as "const" or "pure"
-------------------------+--------------------------------------------------
Reporter: olly | Owner: olly
Type: enhancement | Status: assigned
Priority: normal | Milestone: 1.2.x
Component: Other | Version: SVN trunk
Severity: minor | Resolution:
Keywords: | Blockedby:
Platform: All | Blocking:
-------------------------+--------------------------------------------------
Old description:
> 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
New description:
GCC allows functions to be annotated 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.
attribute((const)) is available for (at least) GCC 2.95 onwards, which is
all the versions we support. MSVC doesn't seem to have an equivalent.
I've not looked at other compilers.
----
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, which covers all the
versions we support for 1.1.x and higher.
MSVC doesn't seem to have an equivalent. I've not looked at other
compilers.
----
Both GCC and MSVC support nothrow - this is now ticket #454.
----
GCC also allows functions to be marked listing pointer parameters which
can't be NULL, which may be worth considering, or perhaps
such parameters should be changed to references.
URL: http://gcc.gnu.org/onlinedocs/gcc-4.1.2/gcc/Function-Attributes.html
#Function-Attributes
--
Comment(by olly):
Hmm, I created #454 for nothrow without realising we already had a ticket.
Since we're unlikely to address all of these at once, it seems useful to
have a separate ticket, so removing nothrow from this one.
--
Ticket URL: <http://trac.xapian.org/ticket/151#comment:9>
Xapian <http://xapian.org/>
Xapian
More information about the Xapian-tickets
mailing list