【发布时间】:2014-01-18 13:22:00
【问题描述】:
考虑这些 C 函数:
#define INDICATE_SPECIAL_CASE -1
void prepare (long *length_or_indicator);
void execute ();
prepare 函数用于存储指向延迟的long * 输出变量的指针。
在 C 中可以这样使用:
int main (void) {
long length_or_indicator;
prepare (&length_or_indicator);
execute ();
if (length_or_indicator == INDICATE_SPECIAL_CASE) {
// do something to handle special case
}
else {
long length = lengh_or_indicator;
// do something to handle the normal case which has a length
}
}
我正在尝试在 Vala 中实现这样的目标:
int main (void) {
long length;
long indicator;
prepare (out length, out indicator);
execute ();
if (indicator == INDICATE_SPECIAL_CASE) {
// do something to handle special case
}
else {
// do something to handle the normal case which has a length
}
}
如何在 Vala 中为 prepare () 和 INDICATE_SPECIAL_CASE 编写绑定?
是否可以将变量一分为二?
即使在调用prepare ()(在execute () 中)之后写入了out 变量,是否也可以避免使用指针?
【问题讨论】: