是否有一种可移植的方法来标记 1 字节对齐指针?

发布于 2025-01-17 04:15:43 字数 194 浏览 2 评论 0原文

我想创建 2 个具有 1 字节对齐的指针的并集,但我不想存储额外的标记来区分它们。我知道在某些平台上,至少指针的最高有效位未被使用,但将来可能会改变。

请问有人知道一种便携式方法吗?

我希望有一种不会使原始指针无效的技术。也就是说,是否有一个函数,当我将它应用于某个数字 n 时,会释放该数字中的至少一位,而当我“取消应用”它时,会返回原始数字。

I want to create a union of 2 pointers which have 1 byte alignment, but I don't want to store an additional tag, to distinguish them. I know that on some platforms, at least the most significant bit of a pointer is unused, but that might change in the future.

Please does someone know a portable way to do this?

I'm hoping for a technique that does not invalidate the original pointer. That is, is there a function for which when I apply it to some number n, frees up at least one bit in the number and when I "unapply" it, gives me back the original number.

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。
列表为空,暂无数据
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文