BlitzMax Request: Signed Short
BlitzMax Forums/BlitzMax Programming/BlitzMax Request: Signed Short
| ||
OK, Mark, you said you wanted to avoid unsigned data types where possible, so give us signed shorts. I'm in the process of providing an implementation of SDL, and it happens to use signed shorts, so this is neccessary. |
| ||
Well OpenGL uses signed and unsigned shorts too so there's already a way for Blitz to convert to either on an extern function call. |
| ||
Well the problem, Michael, is I need to -get- the signed shorts, not send them. Basically, the case is reading this structure: /* Mouse motion event structure */ typedef struct { Uint8 type; /* SDL_MOUSEMOTION */ Uint8 which; /* The mouse device index */ Uint8 state; /* The current button state */ Uint16 x, y; /* The X/Y coordinates of the mouse */ Sint16 xrel; /* The relative motion in the X direction */ Sint16 yrel; /* The relative motion in the Y direction */ } SDL_MouseMotionEvent; Note the lines for xrel and yrel- the problem is that without signed shorts I cannot really use the relative X and Y mouse positions. Now the simple solution is to just stick unsigned shorts in their place and not use them, but then I'm making no use of a portion of SDL's functionality. |
| ||
Well, read them in as a normal short, then pass them through this: [edit: code was wrong] It's messy (especially in situations like this), but I disagree that signed shorts should be added to the language. It's a legacy datatype with no real use in a modern language. |
| ||
Here are two ways to convert a signed short to an Int.' Human-readable version: Function SignedShortToInt( s:Short ) If s < 32768 Then Return Int(s) Return Int(s) - 65536 End Function ' CPU-friendly version: Function SignedShortToInt( s:Short ) Return (s Shl 16) Sar 16 End Function |
| ||
Shame neither method is that 'clean'. |