Re: Bitval Numbers
- Posted by ghaberek (admin) Mar 16, 2021
- 1036 views
While looking through some C code, I saw bitval(10)
I know this is among bitwise functions. However is the value exactly 10? Usually there is a bit shift like 5 << 1
https://webfocusinfocenter.informationbuilders.com/wfappent/TL2s/TL_lang/source/bitval.htm - A bit string as an integer
I don't think this is a standard function or macro in C. The function you're linking to takes four parameters, and is part of WebFOCUS Reporting Language? I found other "BITVAL" functions on Google as well, but they're for FICO Xpress, Informix, and PascalIO.
If I was wrapping a library for Euphoria how I would go about converting it. Just give the variable the value of 10 if the C code says bitval(10)?
C typdef Enum myEnum { NONE = 0, MY_VAL = BITVAL(10) } MyVal
enum type myEnum NONE = 0, MY_VAL = 10 end enum type
Would my example be the right way of going about this?
What you've run into here is likely a custom macro for whatever you're trying to wrap. The right way to go about this would be to track down the macro's implementation and copy it into a function.
My guess is that it's a "safe" bitshift that clamps the resulting value to some range, like valid 32-bit unsigned integers. If you could point me towards wherever you found this, I could try to track it down.
You can't use functions on enum in Euphoria, only constant. If this macro is doing anything fancy to the number then you may want to use a function to preserve the same behavior.
If the macro is something stupidly simple, like #define BITVAL( b ) ( 1 << b ) (which it might be) then you could just assemble the constant or enum values by hand.
-Greg