Path: utzoo!attcan!uunet!ndsuvax!nenicola
From: nenicola@ndsuvax.UUCP (Steven Nicolai)
Newsgroups: comp.windows.misc
Subject: Re: Questions Re MS-Windows Dev Cost
Message-ID: <1362@ndsuvax.UUCP>
Date: 23 Sep 88 22:30:02 GMT
References: <8520002@hp-lsd.HP.COM> <18185@mirror.TMC.COM>
Reply-To: nenicola@ndsuvax.UUCP (Steven Nicolai)
Organization: North Dakota State University  Fargo, ND
Lines: 51

In article <18185@mirror.TMC.COM> mguyott@prism.TMC.COM (Marc Guyott) writes:
>In article <8520002@hp-lsd.HP.COM> davek@hp-lsd.HP.COM (Dave Kumpf) writes:
>>I have some (maybe stupid) questions regarding MS-windows development.
>>
>>1) Why is MS-C required?
>>
>
>Probably to supply the CodeView support for debugging.

That is one reason.  The other reason is that Windows requires different
function prolog and epilog code.  There are actually three different
sets that could be used depending on how the function is called.  Petzold
talks about these in Chapter 8, Memory Management.  Basically there is
one convention for near procs called only from C, a different convention
for far procs called from C, and a third for far procs called from Windows.
(This last type includes window definition functions)  The compiler
actually emits the same code for that last two, and the LINK4 linker
changes the prolog and epilog code.

The near function prolog and epilog code is pretty standard.  The far
function code is kinda neat, they inc bp before pushing in on the stack.
This "feature" allows Windows to walk the stack back through the bp chain
and find all the functions.  They are then able to look at the bp value
on the stack, if it is even they know it was a near function call, if
it was odd, it was a far function call.

Why is this info needed you ask?  Windows swaps segments.  It can even
swap out a segment that has function with a stack frame that is active.
The return address to this function becomes invalid when that segment
is unloaded.  They replace the return address with the address of the
"reload" thunk for the function that was called.  (And you always wondered
why MS-Windows ran sooooo slow....:-)

>>It seems to me (not knowing enough about C) that
>>if you have a linker that understands the Windows LIB and  if your compiler
>>supports PASCAL calling sequences, you should be able to use that C
>>compiler.  (Or does Windows depend on what the compiler does with registers?)

>I would be curious to know what the answer to this question is.

I think this is answered above.  One more comment, Supposedly ZorTech
is working on Windows support for their C++ compiler.  All that is needed
is a switch to turn on this different prolog - epilog code for far functions,
and to follow the MS C calling conventions.  Neither of these sound too
difficult to do.

STeve
-- 
Steve Nicolai                    USMAIL:   1717 40th St SW Apt 106
ARPA & UUCP: nenicola@plains.NoDak         Fargo, ND  58103
BITNET:      nenicola@ndsuvax              (701)-281-1230