我想知道c中有哪些类型.例如,我该怎么做这样的事情.
type type_a = int;
type type_b = float;
Run Code Online (Sandbox Code Playgroud)
在我的项目的上下文中,我正在尝试创建一个可以如下使用的函数.
// createSelector(const char *name, ...)
Selector *mySelector = createSelector("myMethod", int, char);
// Selector->types contains all the passed types in an array.
// Selector->name contains the name of the method.
Run Code Online (Sandbox Code Playgroud)
如果c不支持此功能,我可以轻松地将我的项目转移到c ++.但是,我需要知道c ++中的类型是什么.任何帮助,将不胜感激.
在我正在编写的虚拟机中,我希望能够以类似于以下伪代码的方式调度命令.
add: reg[memory[pc+1]] = reg[memory[pc+1]] + reg[memory[pc+2]]; pc += 2; goto done;
sub: reg[memory[pc+1]] = reg[memory[pc+1]] - reg[memory[pc+2]]; pc += 2; goto done;
cmp: /* Would take more space than simply x = x + y; */ goto done;
for(int pc = 0; memory[pc] != END; pc++) {
goto currentPositionInMemorySomehow + (memory[pc] * lengthOfInstruction);
done:
}
Run Code Online (Sandbox Code Playgroud)
其中memory是包含字节码的数组,pc是程序计数器.但要做到这一点,我们要求跳转到的每个位置在下一个块之前具有完全相同的指令数.除非有一个很棒的平台无关的汇编代码,否则不能选择下载到汇编代码,这样就可以使用相同的代码并编译到Linux,Mac和Windows.无论每个处理器都坐在上面.任何和所有的帮助将不胜感激.