The following warnings occurred:
Warning [2] Undefined array key 0 - Line: 1677 - File: showthread.php PHP 8.2.31 (Linux)
File Line Function
/inc/class_error.php 157 errorHandler->error
/showthread.php 1677 errorHandler->error_callback
/showthread.php 916 buildtree




Thread Rating:
  • 0 Vote(s) - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
Line of sight
#15
I usually code in C, and I can assure you that this code works as intended Smile

Code:
#include <stdio.h> void main (void) { unsigned char lsb = 0; unsigned char msb = 60; unsigned int address; unsigned char x = 0, cx = 100; int dx; address = lsb + (msb << 8); printf ("%d\n", address); dx = x - cx; printf ("%d\n", dx); }

15360 and -100 are printed on screen. This works in any C compiler I've tried so far (z88dk and gcc).

Freebasic also works this way:

Code:
Dim as uByte lsb, msb Dim as uInteger address Dim as uByte x, cx Dim as Integer dx lsb = 0: msb = 60 x = 0: cx = 100 address = lsb + (msb Shl 8) Print address dx = x - cx Print dx

Also prints 15360 and -100. Usually, operands are automaticly casted to the result type. This also works when calling a function. This should print -100:

Code:
Sub printMe (a as Integer) Print a End Sub Dim as uByte x, cx x = 0: cx = 100 printMe (x-cx)

Anyways, good to know about Cast. I should read the docs more often...

Boriel Wrote:[...]as far as I know, dx variable is positive only if x is ALWAYS >= cx. I will use CAST(Uinteger, x) to avoid this problem.

It doesn't work correctly, I've just found it. Instead of

Code:
Draw x - cx, y - cy

With all variables involved typed "uByte", DRAW always draws up and right (i.e.: positive). So I changed it to:

Code:
dx = x - cx: dy = y - cy Draw dx, dy

With dx and dy typed Integer. Stil didn't work. dx and dy were always positive. I had to do this:

Code:
dx = x: dx = dx - cx dy = y: dy = dy - cy Draw dx, dy

And then it worked.
Reply


Messages In This Thread

Forum Jump:


Users browsing this thread: 1 Guest(s)