Re: Bitval Numbers

new topic     » goto parent     » topic index » view thread      » older message » newer message
Icy_Viking said...

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 - 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.

Icy_Viking said...

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)?

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.


new topic     » goto parent     » topic index » view thread      » older message » newer message


Quick Links

User menu

Not signed in.

Misc Menu