Usage of ANSI-C |const| in X11 code...

Adam Jackson ajax at nwnk.net
Sat Mar 12 11:37:27 PST 2005


On Saturday 12 March 2005 13:51, Roland Mainz wrote:
> Yeah, but note the underscore (indicating that it's more some
> (semi-)private stuff) - |_Xconst| is more a hack for the old days when
> K&R compilers needed to be supported. Since a while ANSI-C89 support is
> the minimum required and some code in libX11, Xserver and other places
> already uses |const| without causing complains. So my question is
> whether code can now "officially" use |const| directly (CC:'ing
> xorg-arch at lists.x.org as this is more an architecture question, IMO we
> need need a clear statement that ANSI-C89 is now the minimum level and
> all it's features[1] can be used by Xorg code) ...

Can anyone even name a compiler shipped in the last ten years for any major 
operating system that didn't include ANSI C support?

> [1]=Next question would be whether the |inline| keyword can be used in
> Xorg code - |inline| is newer than ANSI C89 (maybe C99 but I am not
> sure) but most compilers incl. gcc, Sun Workshop/Forte/One and the MS
> compiler support it right now...

Specifying inline is rarely worth the effort, for a few reasons.  The compiler 
will usually ignore your suggestion and inline what it feels like anyway.  
Also, unless your function is also static, you have to emit an out-of-line 
version of the function anyway since it could be called from another 
compilation unit, so that's N+1 copies of the function body.  For most modern 
processors, cache misses are much more expensive than function calls, so 
inlining can actually make your code slower.

It's kind of like the register keyword.  If it makes you feel better, you can 
add it to your declarations, but it's really not going to change anything.  
If we find performance-critical code where inlining makes a difference for a 
given compiler, we should handle that case-by-case, because heuristics differ 
and what's fast in gcc may be slow in sun c.

- ajax
-------------- next part --------------
A non-text attachment was scrubbed...
Name: not available
Type: application/pgp-signature
Size: 189 bytes
Desc: not available
URL: <http://lists.x.org/archives/xorg/attachments/20050312/70f0e91e/attachment.pgp>


More information about the xorg mailing list