Re: [PECL-DEV] Endianness in PHP
[email protected] ("J. Adams")
| Newsgroups | php.pecl.dev |
|---|---|
| Message-ID | <[email protected]> |
Thanks so much for all the assistance and commentary. I really appreciate it. I agree that it would be helpful to have some standardized macros for dealing with endianness. Dealing with it at run-time seems a bit more reliable than relying on one's autoconfigure macro running properly and supplying the correct value. It also mostly skirts the issue of middle-endian machines -- although might there be circumstances under which the endianness changes after the check is made? My thinking is that regardless of how we detect the system's endianness within our application, it would be most helpful to have a canonicalised method for rearranging bytes which ensures cross-platform compatibility for the various affected data types and their varying lengths. For instance, is a long 32 bits or 64? Will ntonl, etc. work properly on a long that's 64 bits? Seems to me like we could do ourselves a favor by introducing some utilities for endian management. Otherwise, you have knuckleheads like me doing it on our own. Melanie Rhianna Lewis wrote: > On 12 Aug 2010, at 12:48, Johannes Schlüter wrote: > > >> Hi, >> >> On Thu, 2010-08-12 at 11:42 +0100, Melanie Rhianna Lewis wrote: >> >>> You can easily detect endianness as follows: >>> >>> Either: >>> >> [...] >> >> Please don't reinvent the wheel. As said in my other mail we have a >> compile time constant for this already. >> > > Sorry I missed that. > > However that's a compile time constant. Mine are run time. > > >> And yes, for all circumstances a compile time value isn't enough. >> Thinking about cross-compiling and MacOS's binaries which support >> PowerPC and Intel architectures but using the provided constants gives a >> consistent behavior. >> > > But are there mapping macros to aid endian translation? If not it would be nice if there were to save each extension that needs it re-inventing the wheel. > > Melanie > > > > >