About Monkey 2 › Forums › Monkey 2 Programming Help › is there a more transparent way to use a C float*
This topic contains 5 replies, has 2 voices, and was last updated by
codifies
2 years, 2 months ago.
-
AuthorPosts
-
January 26, 2017 at 12:21 pm #6822
This is really just a sanity check as I’m not terribly satisfied with the fugliness I’ve come up with (hoping I’ve missed a trick or forgotten something)…
[/crayon]Monkey12345678[crayon-5cba843553dd4721921952 inline="true" ]externStruct cfloat="float"end structfunction func:cfloat ptr()When I want a mx2 float pointer from this function I’m doing
[/crayon]Monkey1234[crayon-5cba843553ddb875045803 inline="true" ]local fptr:float ptr = Cast<float Ptr>( func() )print fptr[3]+","+fptr[0]+","+fptr[1]+","+fptr[2]Which just seems a little less satisfying than it could be ? (especially the cfloat “struct”)
although the parser is fine with me using float ptr in the prototype (instead of cfloat ptr) it misses the issue this causes with the compiler (basically it can’t cast a float* to bb_float* I’m hoping this is where I’m missing a possible clue)
January 27, 2017 at 9:01 pm #6841Not sure why you’re bothering with the cfloat struct at all there…
mx2 floats *are* just c floats (ie: 32bit) and mx2 doubles are just c doubles (ie: 64bit) – in fact, your code already depends on this as it’s casting cfloat ptr to float ptr – so the cfloat struct is redundant as far as I can see.
January 28, 2017 at 12:59 am #6846I just got errors about not being able to cast a float* for a bbfloat* or similar – there does seem to be differences between mingw gcc and more up to date versions (v6.3.0 here)
I’ll try again and see if I can induce the error…
January 28, 2017 at 1:03 am #6847[/crayon]Monkey123[crayon-5cba84355be22643606438 inline="true" ]error: invalid conversion from 'const dReal* {aka const float*}' to 'bbFloat* {aka float*}' [-fpermissive]ah hang on it itsn’t that const thing again is it?
January 30, 2017 at 8:52 pm #6871Yes, looks like a const thing. Your initial solution is probably as good as it gets without resorting to native glue code, which would be cleaner but a little trickier.
January 30, 2017 at 9:15 pm #6873wouldn’t this add over head ? – ie two calls per API call rather than 1 ? (but I might have misunderstood!)
also I assume
[/crayon]Monkey1234[crayon-5cba84355f993271647050 inline="true" ]Struct cfloat="const float"End Structis more technically correct but out of interest will it actually make any difference ?
-
AuthorPosts
You must be logged in to reply to this topic.