Hi Marcel, Not that I know of. With regard to your original question. NativeCall has nativecast (as above) for casting and a CUnion representation for unions. There are some tests in https://github.com/rakudo/rakudo/blob/nom/t/04-nativecall/13-union.t for this.
NativeCall is letting you get pretty close to the metal. Should be fast, but the same dangers and caveats apply, to doing this directly in C. - David On Tue, Apr 12, 2016 at 6:51 PM, JuhiMarcel LangbroekTimmerman < mt195...@gmail.com> wrote: > Hi David, > > Thanks very much for your code, I will try it when I get home at the end > of the week although I only have little endian Intell chips. I will have to > look around for others. Btw, are there still chips storing big endian > paired in two bytes? So your example number would become 0x23, 0x01, 0x67, > 0x45 ? > > Thanks again, > Marcel > > On April 11, 2016 9:45:13 PM David Warring <david.warr...@gmail.com> > wrote: > >> Hi Marcel, >> With regard to checking for endianess. I don't think there's anything >> built in NativeCall that directly determines this, but hopefuly the >> following should do it, without resorting to a C compiler. >> >> use NativeCall; >> sub little-endian returns Bool { >> my $i = CArray[uint32].new: 0x01234567; >> my $j = nativecast(CArray[uint8], $i); >> say sprintf("j[0]:%x j[3]:%x", $j[0], $j[3]); >> $j[0] == 0x67; >> } >> >> say "little-endian:" ~ little-endian; >> >> I've only tested this on a little endian architecture. >> >> Source: I ported the 'C' answer to this SO question: >> http://stackoverflow.com/questions/12791864/c-program-to-check-little-vs-big-endian >> >> >> >> On Tue, Apr 12, 2016 at 6:30 AM, Marcel Timmerman <mt1...@gmail.com> >> wrote: >> >>> Hi >>> >>> Thanks for your answer. I was thinking in perl6, I should have been more >>> explicit. At the moment I am converting Num to a float representation in >>> my >>> BSON module and was wondering if there where easier ways and maybe >>> faster too. >>> >>> Regards, >>> Marcel >>> >>> >>> >>> >>> >>> >>> --- Forwarded message --- >>> From: Marcel Timmerman <mt1...@gmail.com> >>> Date: April 11, 2016 8:28:22 PM >>> Subject: Re: Union >>> To: Parrot Raiser <1parr...@gmail.com> >>> >>> Hi >>> Thanks for your answer. I was thinking in perl6, I should have been more >>> explicit. At the moment I am converting Num to a float representation in >>> my >>> BSON module and was wondering if there where easier ways and maybe >>> faster too. >>> >>> Regards, >>> Marcel >>> >>> >>> >>> >>> >>