Mail Archives: djgpp/1999/05/28/07:40:59
From: | XXguille AT XXiies DOT XXes (Guillermo Rodriguez Garcia)
|
Newsgroups: | comp.os.msdos.djgpp
|
Subject: | Re: mouse problem!
|
Date: | Fri, 28 May 1999 10:59:16 GMT
|
Organization: | Telefonica Transmision de Datos
|
Lines: | 37
|
Message-ID: | <374df1b6.2220679@noticias.iies.es>
|
References: | <7ikl66$gal$1 AT nnrp1 DOT deja DOT com>
|
NNTP-Posting-Host: | iies210.iies.es
|
Mime-Version: | 1.0
|
X-Newsreader: | Forte Agent 1.5/32.451
|
To: | djgpp AT delorie DOT com
|
DJ-Gateway: | from newsgroup comp.os.msdos.djgpp
|
Reply-To: | djgpp AT delorie DOT com
|
El día Thu, 27 May 1999 23:40:54 GMT, nj210337 AT stmail DOT staffs DOT ac DOT uk
escribió:
> *xinc = (int)regs.w.cx;
> *yinc = (int)regs.w.dx;
Just change these casts to
*xinc = (short)regs.w.cx;
*yinc = (short)regs.w.dx;
Because the previous one says to the compiler "interpret this 16-bit
value as if it (already) was an int" (so it doesn't expand sign to
32-bit). And what it should say is "interpret this 16-bit value as
being a signed short, so please expand it to a 32-bit int and of
course pay attention to the sign".
Test this:
#include <stdio.h>
int main (void)
{
unsigned short x = 0xFFFF;
int a, b;
a = (int)x; /* wrong */
b = (short)x; /* right */
printf("Look: %d %d", a, b);
return 0;
}
Regards,
GUILLE
----
Guillermo Rodriguez Garcia
XXguille AT XXiies DOT XXes (ya sabes :-)
- Raw text -