Hi and loword

Got an idea for enhancing PureBasic? New command(s) you'd like to see?
Edwin Knoppert
Addict
Addict
Posts: 1073
Joined: Fri Apr 25, 2003 11:13 pm
Location: Netherlands
Contact:

Hi and loword

Post by Edwin Knoppert »

I don't understand why a simple hi and loword aren't available at this time?

Afaik i made this request years ago..?

This is simpliest new feature one can bring to the compiler..

(I am aware of the workarounds)
Trond
Always Here
Always Here
Posts: 7446
Joined: Mon Sep 22, 2003 6:45 pm
Location: Norway

Post by Trond »

It's called PeekW().
Edwin Knoppert
Addict
Addict
Posts: 1073
Joined: Fri Apr 25, 2003 11:13 pm
Location: Netherlands
Contact:

Post by Edwin Knoppert »

You understand that the result might be the same but it isn't the same..

I mean i now have use pointer to variable + 2 bytes for lo or hi word.
Last edited by Edwin Knoppert on Sat May 19, 2007 5:16 pm, edited 1 time in total.
Edwin Knoppert
Addict
Addict
Posts: 1073
Joined: Fri Apr 25, 2003 11:13 pm
Location: Netherlands
Contact:

Post by Edwin Knoppert »

o btw, most of us won't know what bytes represent hi or low.
I have to look that up.

This is just another workaround for something obvious.
Trond
Always Here
Always Here
Posts: 7446
Joined: Mon Sep 22, 2003 6:45 pm
Location: Norway

Post by Trond »

What on earth would you need this for?
I mean i now have use pointer to variable + 2 bytes for lo or hi word.
Common!!
You don't need to use a separate pointer: PeekW(@Variable+2)
Edwin Knoppert
Addict
Addict
Posts: 1073
Joined: Fri Apr 25, 2003 11:13 pm
Location: Netherlands
Contact:

Post by Edwin Knoppert »

Ever broken a wm_command's parameter in two?
KarLKoX
Enthusiast
Enthusiast
Posts: 681
Joined: Mon Oct 06, 2003 7:13 pm
Location: France
Contact:

Post by KarLKoX »

Code: Select all

Macro LOWORD(Value)
  Value & $FFFF
EndMacro

Macro HIWORD(Value)
  (Value >> 16) & $FFFF
EndMacro 
:?:
"Qui baise trop bouffe un poil." P. Desproges

http://karlkox.blogspot.com/
Edwin Knoppert
Addict
Addict
Posts: 1073
Joined: Fri Apr 25, 2003 11:13 pm
Location: Netherlands
Contact:

Post by Edwin Knoppert »

>(I am aware of the workarounds)

It seems better to argue than to implement this silly but helpful feature?
It's NOT that i want a macro in my app but a structural availability in the compiler.
User avatar
ts-soft
Always Here
Always Here
Posts: 5756
Joined: Thu Jun 24, 2004 2:44 pm
Location: Berlin - Germany

Post by ts-soft »

HiWord, LoWord and some other a implemented as macro in the win API, see the windows-headers, why not use Macros in PB :o
Native support for this only in languages, that doesn't support macro's
PureBasic 5.73 | SpiderBasic 2.30 | Windows 10 Pro (x64) | Linux Mint 20.1 (x64)
Old bugs good, new bugs bad! Updates are evil: might fix old bugs and introduce no new ones.
Image
Fred
Administrator
Administrator
Posts: 18162
Joined: Fri May 17, 2002 4:39 pm
Location: France
Contact:

Post by Fred »

We could add this in the Windows resident as Macro, it's not that useful except when dealing with crappy designed WinAPI.
Edwin Knoppert
Addict
Addict
Posts: 1073
Joined: Fri Apr 25, 2003 11:13 pm
Location: Netherlands
Contact:

Post by Edwin Knoppert »

>We could add this in the Windows resident as Macro
Whatever, as long it becomes nativly available..

>, it's not that useful except when dealing with crappy designed WinAPI.
Certainly not my opinion, pb has it's flaws as well.
thefool
Always Here
Always Here
Posts: 5875
Joined: Sat Aug 30, 2003 5:58 pm
Location: Denmark

Post by thefool »

Edwin Knoppert wrote: >, it's not that useful except when dealing with crappy designed WinAPI.
Certainly not my opinion, pb has it's flaws as well.
Come on, everybody knows that the windows api is a huge mess.. Even microsoft themself! Why would they else replace it with a new framework?
superadnim
Enthusiast
Enthusiast
Posts: 480
Joined: Thu Jul 27, 2006 4:06 am

Post by superadnim »

because managed frameworks provide you with an extra layer of security and ultimately portability.
Trond
Always Here
Always Here
Posts: 7446
Joined: Mon Sep 22, 2003 6:45 pm
Location: Norway

Post by Trond »

Megabump there!

I take back what I said, not because using PeekW() isn't easy, but because it's hard to remember which part is high and which is low.

I also like the Windows API, by the way, although it has a few flaws like this.
User avatar
Rescator
Addict
Addict
Posts: 1769
Joined: Sat Feb 19, 2005 5:05 pm
Location: Norway

Post by Rescator »

Code: Select all

Macro LOWORD(a) : (a&$ffff) : EndMacro
Macro HIWORD(a) : ((a>>16)$ffff) : EndMacro
Macro MAKELONG(a,b) : ((a&$ffff)+b<<16) : EndMacro
I think these are correct?. (forgot a mask on HIWORD though, thanks KarLKoX)

These are from my BASS.pbi (for the BASS audio library)
It's needed for example for getting the version of the libary (it's returned as a long but the long is actually two words)

Yeah I know, a pointer to a structure is much better solution than LOWRD and HIWORD etc. but...
I do seem to run into these from time to time. (WinAPI and various C/C++ libs)
Post Reply