Mail Archives: djgpp/1996/09/01/04:17:24
Morten Welinder wrote:
>
> "Bob Platko" <platko AT ix DOT netcom DOT com> writes:
>
> >My code works fine in Borland, but not in DJGPP! What's wrong?
>
> Your program.
[snip]
> So you are passing a pointer to the wrong kind of object to scanf().
> Therefore scanf() overwrites memory you did not mean to.
>
> Nuke the "short" and you will have a correct program.
I'd like to mention, just in case you were going to ask, that the reason
for this behavior is that Borland is a 16-bit compiler while djgpp is a
32-bit compiler. Thus, in BC sizeof(int) == sizeof(short), while in
djgpp sizeof(int) == sizeof(long). The reason your code worked in BC
is that %u and %hu both refer to similarly sized objects, while in
djgpp they do not. You should always use the correct format specifier
even if a given implementation makes it unnecessary. Compiling with
-Wall as mentioned above will guarantee that the compiler will warn you
when you forget this.
> Morten
>
> PS: There are some problems with scanf() if I remember things
> right. They have to do with the return value and are being
> worked on or have already been solved for the next release.
I think most of these have been solved; check out the djgpp bug tracking
system for more details. However they mostly only show up when reading
from files as opposed to from the console.
--
John M. Aldrich, aka Fighteer I <fighteer AT cs DOT com>
-----BEGIN GEEK CODE BLOCK-----
Version: 3.1
GCS d- s+:- a-->? c++>$ U@>++$ p>+ L>++ E>+ W+>++ N++ o+ K? w(---) O-
M-- V? PS+ PE Y+ PGP- t+(-) 5- X- R+ tv+() b+++ DI++ D++ G e(*)>++++
h!() !r !y+()
------END GEEK CODE BLOCK------
- Raw text -