Mail Archives: djgpp/1998/04/15/17:07:52
From: | "Aleksey Kondratyev" <akondra AT mv DOT ru>
|
Newsgroups: | comp.os.msdos.djgpp
|
Subject: | Re: A bug in djgpp?
|
Date: | Wed, 15 Apr 1998 23:21:43 +0400
|
Organization: | Middle Volga Communication service
|
Lines: | 41
|
Message-ID: | <6h31jn$gqa$1@simtel.ru>
|
References: | <01bd6885$7fe38c40$a1d06ccb AT bah>
|
NNTP-Posting-Host: | ppp133.usr.mv.ru
|
To: | djgpp AT delorie DOT com
|
DJ-Gateway: | from newsgroup comp.os.msdos.djgpp
|
Tom Wilson wrote
>Hi People :I
>
>I'm a newbie C programmer using djgpp, and while mucking about i found
>something weird and i dont really understand it :)
>
>ok if i compile this peice of code..
>
>#include <stdio.h>
>int main()
>{
> short b, a;
> printf("Choose a value for a: ");
> scanf("%i", &a);
> printf("Choose a value for b: ");
> scanf("%i", &b);
> printf("A is equal to %i\n", a);
> printf("B is equal to %i\n", b);
> return 0;
>}
>
>
>i get the expected results... The program prints the value of A and B that
Try to use "%hi" instead of "%i" in the format string. 'short int' occupies
2 bytes in DJGPP but scanf treats your variables as 4 bytes integers.
Probably, it may cause unpredictable consequences. This problem will
appear using any compiler where short int and int are of different size.
Regards, Aleksey
----------------------------------------------------------------------
Aleksey Kondratyev
Ph.D. student of Ulyanovsk state University
http://www.mv.ru/~akondra
e-mail:akondra AT mmf DOT univ DOT simbirsk DOT su
- Raw text -