detecting if an atom is a pointer
- Posted by Chris Bensler <bensler at nt.net> Nov 15, 2006
- 539 views
The problem: A set of routines that accept an atom as a parameter, which could be a pointer or a type identifier. The type identifiers are Eu's C type definitions.. C_INT, C_FLOAT, etc.. All the Eu definitions are in the format #0F00000F where #0F000000 represents the type modifier and #0000000F represents the atomic size. I've expanded the definitions to support compound C types. (structs, unions, arrays and bitfields) The mask format for the expanded identifiers is #CFFFFFFF As you can see, the expanded identifiers use pretty much all the bits of the atom. (bits 27 and 28 are not used) My first thought was to use the pointer alignment to detect the difference, since an identifier will always use at least 1 of the aligned bits for the type size. This is flawed however because the type size could be 8, which would use 4 bits and the 3 aligned bits would be 0. Additionally, it would be preferable if it will handle third party allocations as well as Eu pointers, and AFAIK there is no guarantee that third party pointers will be aligned at all. So the question: is there a way that I can determine if an atom is a pointer or an identifier? In my testing it appears that the pointers never use all the high bits. Is this because Eu's heaps? or OS heaps? Would it be safe to use those bits to detect identifiers? Chris Bensler ~ The difference between ordinary and extraordinary is that little extra ~ http://empire.iwireweb.com - Empire for Euphoria