digitalmars.com                        
Last update Sun Mar 4 11:58:07 2018

Windows Prolog/Epilog Code Generation

From the IDDE, use the Windows Prolog/ Epilog subpage on the Build page of the IDDE's Project Settings dialog box.

32 Bit Windows Prolog/Epilog Code Generation

Win32 Switches
Switch Description
-WA Win32 EXE
-WD Win32 DLL
no -W switch Win32 console EXE app

16 Bit Windows Prolog/Epilog Code Generation

-W{0123ADabdefmrsuvwx-+}
Switch Description
-W Same as -W1 if no modifier switches
-W- Not a windows compile (default)
-W1 Real mode Windows app/DLL
-W2 Real mode Windows app/DLL with exported and callback functions marked with __export
-W3 Real mode Windows app with smart callbacks
-WA Protected mode Windows EXE, with callback functions all marked as __export.
-WD Protected mode Windows DLL, with callback and exported functions all marked as __export.
Modifiers
Modifier Description
a Reload DS from DS for far functions
b Assume DS != DGROUP
d Reload DS from DGROUP for far functions
e Generate EXPDEF records in .OBJ file for __export functions
f Mark all far functions as __export
m Generate INC BP / DEC BP to mark far stack frames
r Generate reload of DS only if __export or __loadds functions
s Reload DS from SS for far functions (smart callbacks)
t Use fixups instead of CS. This is needed for real mode, where selector values can change as code moves around.
u Reload DS from DGROUP for near and far functions (same as -mu) (same as marking all functions as __loadds)
v Save/restore caller's DS in far functions
w Assume SS != DS (same as -mw)
x Program will be run under Windows
- Turn off subsequent modifiers
+ Turn on subsequent modifiers

Modifers a,d,s,v are mutually exclusive.

Equivalents
Switch Equivalent
-W1 -Wtxema -D_WINDOWS
-W2 -Wtxemar -D_WINDOWS
-W3 -Wtxems -D_WINDOWS
-WA -Wtxrs -D_WINDOWS
-WD -Wtxerdw -D_WINDOWS -D_WINDLL
-WD-r -Wtxedw -D_WINDOWS -D_WINDLL

Recommended:

Don't Do This:

Microsoft C6 switch compatibility for Windows compiling:

MSC DMC Description
-Gw -W Full Windows prolog/epilog for far functions
-GW -W2 Reduced prolog/epilog, Note 1
-Au -mwu assume SS != DS and load DS on each function
-Aw -mw assume SS != DS

Note 1: DMC will still generate the full prolog/epilog for __far __export functions, MSC6 will not.

Microsoft C7/VC switch compatibility for Windows compiling:

MSC DMC Description
-Gw -W Full Windows prolog/epilog for far functions
-Au -mwu assume SS != DS and load DS on each function
-Aw -mw assume SS != DS
-GA -WA optimized protected mode Windows apps
-GD -WD optimized protected mode Windows DLLs
-GEa -Wa load DS from AX
-GEd -Wd load DS from DGROUP
-GEe -We emit EXPDEF records for all exported functions
-GEf -W-r create prolog/epilog code for all far functions
-GEm -Wm add inc BP / dec BP to prolog / epilog of far functions
-GEr -W2v real mode, reduced prolog for non-exported functions
-GEs -Ws load DS from SS
-Gq -Wtxme compatibility with MSC6 -GW
-GW -Wtxmev -D_WINDOWS reduced prolog for real mode Windows functions

Special Feature

The -Wb switch (assume DS != DGROUP) causes the compiler to issue a warning whenever a segment fixup is done to DGROUP. If your program is using an alternate data segment, this could mean that a DGROUP fixup is a program bug.

A DGROUP fixup can be triggered (in large data model) by things like:

static int x;
static int *px = &x; /* DGROUP fixup generated */
static char *p = "abc"; /* DGROUP fixup generated */

To get rid of the fixup, the pointers can be made near:

static int __near *px = (int __near *)&x;
static char __near *p = "abc";

These will generate DGROUP relative fixups, not DGROUP segment fixups. Alternatively, the pointers can be initialized at runtime (the compiler generates code that uses DS to initialize segment values).

Eliminating DGROUP segment fixups is useful for:

The -Wb switch can be highly useful in finding difficult to track down bugs in such code. -Wb does not affect code generation at all, it only reports when a DGROUP segment fixup is generated.

Note that -Wb will issue errors if you are using __loadds (because DS is reloaded from DGROUP) or if you are using -Wd (load DS from DGROUP Windows prologs).

-W tells the compiler to ignore case when linking to make the programs more compatible with existing Windows programs (many of which are linked that way). When developing new programs, do not ignore case, since C and C++ are case-sensitive languages. Ignoring case can cause bugs that are difficult to trace.

To compile a Windows program without ignoring case, use the options -W -L/noi

dmc -W -L/noi winprog.c 

References For 16 Bit Windows Prolog/Epilogs

Chapter 21
"Programmer's Reference, Volume 1"
Microsoft Windows SDK 3.1

Chapters 7 and 19
Programming Windows 3.1, Third Edition
Charles Petzold
Microsoft Press
ISBN 1-55615-395-3

Home | Runtime Library | IDDE Reference | STL | Search | Download | Forums