字节序操作 - 有一个C库呢? [英] Endianness manipulation - is there a C library for this?

查看:134
本文介绍了字节序操作 - 有一个C库呢?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

使用的那种我写程序(使用原始档案资料工作)我经常需要功能大,小尾数之间进行转换。通常我写这些我自己(这是由很多其他职位包括在这里),但我不是这样做了一些原因,敏锐 - 主要的一个是缺乏测试。我真的不想花年龄测试我的code在大端模拟器,并往往只是省略了code为大端机器完全。我也宁愿利用各种编译器提供更快的功能,同时仍保持我的程序跨平台的。

With the sort of programs I write (working with raw file data) I often need functions to convert between big and little endian. Usually I write these myself (which is covered by many other posts here) but I'm not that keen on doing this for a number of reasons - the main one being lack of testing. I don't really want to spend ages testing my code in a big endian emulator, and often just omit the code for big endian machines altogether. I also would rather make use of faster functions provided by various compilers, while still keeping my programs cross-platform.

唯一的东西我能看到的是插座调用,例如htons(),但他们要求每个平台上不同的#include文件,以及一些GPL code的like这个,但该特定文件,而COM prehensive,似乎错过了一些高性能某些编译器提供的功能。

The only things I can find are socket calls like htons() but they require different #include files on each platform, and some GPL code like this, however that particular file, while comprehensive, seems to miss out on some of the high performance functions provided by some compilers.

因此​​,没有人知道这是很好的测试库(最好只是.h文件),并提供一组标准的功能与字节顺序在许多编译器和平台处理?

So, does anyone know of a library (ideally just a .h file) that is well tested and provides a standard set of functions for dealing with endianness across many compilers and platforms?

推荐答案

目前已经有许多用于升压类提案(对于C ++,至少)做的正是在过去的十年中,但没有曾经来瓜熟蒂落,很遗憾。

There have been a number of proposals for a Boost class (for C++, at least) to do exactly that over the last decade, but none have ever come to fruition, unfortunately.

我不知道比htons()函数设置什么更好的广义的解决方案。

I'm not aware of any better generalized solution than the htons() function set.

这篇关于字节序操作 - 有一个C库呢?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆