1833 – std.c.windows.windows should use enums for constants, or be more selective about use of extern(Windows)

D issues are now tracked on GitHub. This Bugzilla instance remains as a read-only archive.
Issue 1833 - std.c.windows.windows should use enums for constants, or be more selective about use of extern(Windows)
Summary: std.c.windows.windows should use enums for constants, or be more selective ab...
Status: RESOLVED FIXED
Alias: None
Product: D
Classification: Unclassified
Component: phobos (show other issues)
Version: D1 (retired)
Hardware: x86 Windows
: P2 normal
Assignee: Walter Bright
URL:
Keywords:
Depends on:
Blocks:
Reported: 2008年02月13日 19:51 UTC by Bill Baxter
Modified: 2014年02月24日 15:56 UTC (History)
0 users

See Also:


Attachments
Add an attachment (proposed patch, testcase, etc.)

Note You need to log in before you can comment on or make changes to this issue.
Description Bill Baxter 2008年02月13日 19:51:27 UTC
The phobos module std.c.windows.windows defines many constants like so:
extern(Windows) { 
 ...
 const DWORD MAILSLOT_NO_MESSAGE = cast(DWORD)-1;
 ...
}
This is a bad practice because 
A) all those constants bloat the executables. Using an enum instead fixes that.
B) consts with Windows linkage are mangled without their module name, so if any other module defines the same constant with Windows linkage, the linker will complain of duplicate symbols. This can be fixed either by using enums or by not putting such constants in extern(Windows) blocks.
B may not seem like such a big deal, but a number of fairly high-profile projects (Tangobos and DFL for example) contain copies of std.c.windows.windows that are modified slightly in one way or another. The copied versions of std.c.windows.windows should be fixed too, but Phobos should provide a good example of the "right" way to handle constants to begin with.
Comment 1 Walter Bright 2008年03月04日 02:25:54 UTC
Not all the const declarations can be converted to enums with D 1.0, but I'll do all that can be.
Comment 2 Bill Baxter 2008年03月04日 03:11:37 UTC
(In reply to comment #1)
> Not all the const declarations can be converted to enums with D 1.0, but I'll
> do all that can be.
> 
Thanks. Please use extern(D) on the ones that can't be made enums.
Comment 3 Bill Baxter 2008年03月04日 04:32:40 UTC
(In reply to comment #2)
> (In reply to comment #1)
> > Not all the const declarations can be converted to enums with D 1.0, but I'll
> > do all that can be.
> > 
> 
> Thanks. Please use extern(D) on the ones that can't be made enums.
...unless you've got some good reason why they shouldnt' be extern(D), of course.
Comment 4 Walter Bright 2008年03月07日 00:29:54 UTC
Fixed dmd 1.028 and 2.012


AltStyle によって変換されたページ (->オリジナル) /