Import or inline for uint32_t & byte

Previous topic - Next topic

matchy

I'm wondering what are the data type replacements for these parameters, which are used in Arduino C;
IMPORT uint32_t get_color(byte r, byte g, byte b)
How do you import this function:?  :bed:
Code (glbasic) Select

uint32_t Color(byte r, byte g, byte b) {
uint32_t c;
c = r;
c <<= 8;
c |= g;
c <<= 8;
c |= b;
return c;
}


bigsofty

#1
Try...

Code (glbasic) Select
IMPORT "C" int Color(char r, char g, char b)

untested though.

Oh, and remember your REQUIRE if your not using command line stuff/inlines.
Cheers,

Ian.

"It is practically impossible to teach good programming style to students that have had prior exposure to BASIC.  As potential programmers, they are mentally mutilated beyond hope of regeneration."
(E. W. Dijkstra)

MrTAToad

byte is usually either signed or unsigned char
uint32_t is unsigned int

bigsofty

I could be wrong here but I think you are limited to the type of Types(:S) that IMPORT can use though? So, although these types are not ideal(you have to ignore the sign) I think they should still be usable with GLB.
Cheers,

Ian.

"It is practically impossible to teach good programming style to students that have had prior exposure to BASIC.  As potential programmers, they are mentally mutilated beyond hope of regeneration."
(E. W. Dijkstra)

matchy

I actually tried unsigned int and char and it compiles but it's when it get's called I get an error:  :'(
undefined reference to `__GLBASIC__::Color(char, char, char)

bigsofty

Ouch, could you post your test code?  :whistle:

BTW, I would just convert that little bit of code to inline or GLB syntax but you may be using this function as a template for a more complicated one I assume?
Cheers,

Ian.

"It is practically impossible to teach good programming style to students that have had prior exposure to BASIC.  As potential programmers, they are mentally mutilated beyond hope of regeneration."
(E. W. Dijkstra)

matchy

Alright I am using the ASL command now as it's really the only bitwise operation.