带指针的C程序

C program with pointer

是否可以将任何使用指针的 C 语言程序转换为另一个不包含任何指针的 C 程序?如果是,我们可以自动化该过程吗?

我看了一些c到java字节码编译的论文,发现一个主要问题是"the pointer problem"。所以我在想如果上面的过程可以完成,那么它可以包括预处理步骤(尽管它本身可能是一项艰巨的任务),然后尝试转换为 jvm 字节码可能更简单...

提前致谢

指针是 C 的核心。虽然 C 可能没有指针是图灵完备的,但没有指针重写任意 C 是不切实际的。
你可以做的事情不要没有指针:
-动态(手动)内存分配。
-通过引用传递。

鉴于数组 衰减 转换为指针 a 帽子,你实际上也不能使用数组,所以你剩下的是不能是数组的自动、静态和全局变量。
tl;dr: 没有

理论上你可以,通过用数组模拟单个数据结构甚至整个内存(静态数据、堆和堆栈)。但问题是这是否很实用?它可能涉及必须重写您需要的每个基于指针的标准库函数。

无论如何,Wikipedia 上有一个很好的解释:

It is possible to simulate pointer behavior using an index to an (normally one-dimensional) array.

Primarily for languages which do not support pointers explicitly but do support arrays, the array can be thought of and processed as if it were the entire memory range (within the scope of the particular array) and any index to it can be thought of as equivalent to a general purpose register in assembly language (that points to the individual bytes but whose actual value is relative to the start of the array, not its absolute address in memory). Assuming the array is, say, a contiguous 16 megabyte character data structure, individual bytes (or a string of contiguous bytes within the array) can be directly addressed and manipulated using the name of the array with a 31 bit unsigned integer as the simulated pointer (this is quite similar to the C arrays example shown above). Pointer arithmetic can be simulated by adding or subtracting from the index, with minimal additional overhead compared to genuine pointer arithmetic.