Board index » delphi » Unusual behaviour of console mode vs DOS mode app

Unusual behaviour of console mode vs DOS mode app

Hi folks,

I have an unusual situation I am hoping someone can shed light on
please. I have an application consisting of mixed C and C++ modules.
Within the C modules I am reading the contents of a binary file into a
structure that has fixed size at compile time. If I compile the
application as a DOS standard exe everything works correctly (note the C
code was originally written for a DOS protected mode app) and I get a
structure size of 6638 bytes being correctly read from the file.
However, when I change the target to Windows console the structure size
is now 6670 bytes and the file is not correctly read.

I am using Borland's C/C++ compiler v5.02.

Can anyone suggest why a Windows console mode app would take 32 more
bytes than a DOS mode app to initialise the same data structure and how
I might correct this problem? I have the feeling that the answer is
staring me in the face but I just cannot see it at this time.

Thanks,

Tim
--
___________________________________________
     Tim Wilkin      t...@csse.monash.edu.au
  Aerosonde Project   Ph: +61 3 9905 5139
                     Fax: +61 3 9905 5146
-------------------------------------------
School of Comp. Sci. & Software Eng. &
Department of Mathematics & Statistics,
Monash University, Clayton, Australia. 3800

 

Re:Unusual behaviour of console mode vs DOS mode app


Quote
On Tue, 13 Feb 2001 15:23:09 +1100, Tim Wilkin <t...@csse.monash.edu.au> wrote:
>Can anyone suggest why a Windows console mode app would take 32 more
>bytes than a DOS mode app to initialise the same data structure and how
>I might correct this problem?

Two main causes:
(1) An int is 16-bits in DOS, 32-bits in Win32.
(2) Structure padding/alignment may be set differently during the two builds.

If problem is (1), change the ints in the structure to shorts.
If problem is (2), ensure the structure padding alignment is
as needed by "wrapping" the struct in pragmas.

--
Wayne A. King
(ba...@torfree.net, wayne.k...@ablelink.org,
 wak...@idirect.com, Wayne_A_K...@compuserve.com)

Re:Unusual behaviour of console mode vs DOS mode app


Maybe it is a file translation problem (I experienced it by myself some time
ago...).
The file you read from is text or binary ?
If text use fread(..., "rt" )
If binary use fread(..., "rb" )

Hope it helps you.
Marco

"Tim Wilkin" <t...@csse.monash.edu.au> ha scritto nel messaggio
news:3A88B6AC.5393E090@csse.monash.edu.au...

Quote
> Hi folks,

> I have an unusual situation I am hoping someone can shed light on
> please. I have an application consisting of mixed C and C++ modules.
> Within the C modules I am reading the contents of a binary file into a
> structure that has fixed size at compile time. If I compile the
> application as a DOS standard exe everything works correctly (note the C
> code was originally written for a DOS protected mode app) and I get a
> structure size of 6638 bytes being correctly read from the file.
> However, when I change the target to Windows console the structure size
> is now 6670 bytes and the file is not correctly read.

> I am using Borland's C/C++ compiler v5.02.

> Can anyone suggest why a Windows console mode app would take 32 more
> bytes than a DOS mode app to initialise the same data structure and how
> I might correct this problem? I have the feeling that the answer is
> staring me in the face but I just cannot see it at this time.

> Thanks,

> Tim
> --
> ___________________________________________
>      Tim Wilkin      t...@csse.monash.edu.au
>   Aerosonde Project   Ph: +61 3 9905 5139
>                      Fax: +61 3 9905 5146
> -------------------------------------------
> School of Comp. Sci. & Software Eng. &
> Department of Mathematics & Statistics,
> Monash University, Clayton, Australia. 3800

Other Threads