Hello,

in these days I'm writing simple C programs to study their assembly code. Yesterday looking at how an initialized global variable is represented I was wondering about its position in the .data section. What I was thinking about is if its position varies when the application is run under w2k/wXP compared to when it is run under w9x/wME. Would it's position be the same or would it vary? I know that under w9x/wME systems some C types have a different size (integers for example) and I was wondering if this might cause a given initiliazed global variable to have a different position on different operating systems.

Regards,
yaa
Posted on 2003-03-05 04:03:52 by yaa
as long as you're running x86 code on a 32bit platform with a standard image base, data types will be same size on 9x/NT (can't see why anybody would think this wouldn't be the case), and sections will be laid out on the same adresses.
Posted on 2003-03-05 11:41:10 by f0dder
The size of a data type is determined by the language compiler or interpreter, not by the underlying OS.

As an example, although programs written for Win32, under VB and VC, run as 32-bit programs, VB insists that Integers are still 16-bit (as in older MS days), while VC defines ints to be 32-bits.

Also, the position of data within a given section is determined by the linker (as well as the compiler). It can be affected by the order in which the linked modules are listed.

At the level of executable code, all address references are by position. There is no point to altering them except by a simple addition that is applied to all "absolute" addresses. The x86 is also a pretty conventional processor, where data types are determined by the instructions, and not by type information embedded in a data object. An instruction that adds two 32-bit quantities in one Windows version will add two 32-bit quantities on another.
Posted on 2003-03-06 00:41:42 by tenkey
If I may add to this discussion, I believe (I'm not sure really) that ints on win9x/winME are 2 bytes intead of 4 (I'm talking of VC++ ints) as on winNT/win2K/winXP ... but I don't have a win9x/winME system at my disposal so I can't verify what I'm saying. Could anyone check this up? Thx.

Regards,
yaa
Posted on 2003-03-06 04:56:37 by yaa
I already said that is wrong, yaa.
If you're compiling 16bit code, that's a different story. But you usually do 32bit code for 9x, so...
Posted on 2003-03-06 05:00:00 by f0dder
And I've written VC++ code for Win9x and NT. It's 32-bits for int's under VC6. I use the same executable for both systems with no option flags to distinguish between the two platform types.

As I've more or less said, an ADD instruction that adds 32 bits in XP will add 32 bits in Win98.

If you're talking about Win16 (Windows 3.0 and 3.1), that's a different story. VC6 cannot create executables for that OS. You must use some other compiler. These much older compilers generate Win16 executables (NE format).
Posted on 2003-03-06 13:29:40 by tenkey