例如,为什么有人应该在C/C ++中使用三指针? [英] Example why someone should use triple-pointers in C/C++?

查看:62
本文介绍了例如,为什么有人应该在C/C ++中使用三指针?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在搜索一个示例或解释,为什么有人应该在C/C ++中使用 OR 而不使用三重指针.三指针出现了吗?

I'm searching for an example or explanation why someone should use OR not use triple-pointers in C/C++. Are there any source-code where triple-pointer arise?

谢谢.

特别是我正在寻找使用三指针的源代码.

Especially i'm looking for a source-code which uses triple-pointers.

推荐答案

想到的最好的例子是一个稀疏的多级表.例如,一种实现Unicode字符属性的方法可能是:

The best example that comes to mind is a sparse multi-level table. For instance one way to implement properties for Unicode characters might be:

prop_type ***proptable;
...
prop_type prop = proptable[c>>14][c>>7&0x7f][c&0x7f];

在这种情况下, propable 将需要具有三指针类型(如果最终的结果类型是指针类型,则可能需要四指针).之所以将其作为多个级别而不是一个平面表,是因为在第一层和第二层,当内容全部相同(例如,巨大的CJK范围)时,多个条目可以指向同一个子表.

In this case proptable would need to have a triple-pointer type (and possibly quadruple pointer if the final resulting type is a pointer type). The reason for doing this as multiple levels rather than one flat table is that, at the first and second levels, multiple entries can point to the same subtable when the contents are all the same (e.g. huge CJK ranges).

这是我实现的多级表的另一个示例;我不能说我为该设计感到非常自豪,但是鉴于代码必须满足的约束,它是最糟糕的实现选择之一:

Here's another example of a multi-level table that I implemented; I can't say I'm terribly proud of the design but given the constraints the code has to satisfy, it's one of the least-bad implementation choices:

http://git.musl-libc.org/cgit/musl/tree/src/aio/aio.c?id=56fbaa3bbe73f12af2bfbbcf2adb196e6f9fe264

这篇关于例如,为什么有人应该在C/C ++中使用三指针?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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