logo       

Sponsor
FREE Network Mapping Tool for Microsoft® Office Visio® Professional 2007
Don't map your network by hand - let LANsurveyor Exx press for Microsoft Visio Professional 2007 automatically create network diagrams for you!

Re: Typed constants: msg#00069

freedesktop.xcb

Subject: Re: Typed constants

Ian Osgood wrote:
> It also occurs to me that we could use another method for defining
> constants. Many of the protocol struct-wrapped parameters can take
> "special" values. For example, most places an XCBTIMESTAMP is required,
> people will want to use CurrentTime. Currently this requires an enum
> containing CurrentTime and a local definition;
>
> XCBTIMESTAMP now = { XCBCurrentTime };
>
> to be type-correct. It would be nicer if we could export this kind of
> constant from the library directly. This would be a proto construct like:
>
> <const name="CurrentTime" type="TIMESTAMP"><value>0</value></const>
>
> expanding in header mode to:
>
> extern const XCBTIMESTAMP XCBCurrentTime;
>
> and in source mode to:
>
> const XCBTIMESTAMP XCBCurrentTime = { 0 };
>
> Would this be hard to do? Does this have a downside I'm missing?

This seems like a good idea to me. However, #define does have the
advantage of inlining the constant values, which "extern const"
references won't do. Furthermore, these constants will increase the
disk and memory size of libXCB, even for those constants a given program
doesn't use. Type safety seems like a win, but our current approaches
to type safety don't cost us any speed.

How about defining the constants as "static const" in the header file
instead? The compiler can throw away unreferenced static const values
because no external references can exist that it doesn't know about.
This will avoid adding all the constants to the size of libXCB, and make
programs using these constants bigger by only the size of the constants
they use (albeit potentially repeated, but inlining constants seems like
a feature), and permit inlining.

For that matter, as Yet Another thing we could do if the XSLT calculated
the size of data structures, we could have a heuristic threshold for
when we use "static const" and when we use "extern const". However, if
we ever changed this heuristic and stopped providing any external const
values we previously provided, we'd break the ABI; thus, this seems like
a fragile solution, and we should really just pick one of the two and go
with it.

- Josh Triplett



Attachment: signature.asc
Description: OpenPGP digital signature

_______________________________________________
Xcb mailing list
Xcb-PD4FTy7X32lNgt0PjOBp9y5qC8QIuHrW@xxxxxxxxxxxxxxxx
http://lists.freedesktop.org/mailman/listinfo/xcb



Only community members can participate in forum threads. You must Register or log in to contribute.

<Prev in Thread] Current Thread [Next in Thread>
Sponsor
FREE Network Mapping Tool for Microsoft® OfficeVisio Professional 2007
Don't map your network by hand - let LANsurveyor Express for Microsoft Visio Professional 2007
automatically create network diagrams for you!
Google Custom Search

Free Magazines

Cisco News
Receive a free quarterly e-newsletter with exclusive articles on how Cisco IT uses its own products and solutions to enable the business.
subscribe

Systems Management News, the newspaper for IT systems administration and data center managers! Each issue of Systems Management News is chock-full of news and analysis to help you understand what's happening in your field.
subscribe

The Enterprise Newsweekly eWeek is the essential technology information source for builders of e-business.
subscribe

Oracle Magazine Oracle Magazine contains technology strategy articles, sample code, tips, Oracle and partner news, how to articles for developers and DBAs, and more. Oracle (NASDAQ: ORCL) is the world's largest enterprise software company.
subscribe

Total Telecom Total Telecom is "The Economist of the communications industry".
subscribe

Navigation

Home | sitemap | advertise | OSDir is an inevitable website. super tiny logo