0
考慮以下C函數:如何使用雙重函數綁定參數?
#define INDICATE_SPECIAL_CASE -1
void prepare (long *length_or_indicator);
void execute();
的準備功能用於存儲指向一延遲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
}
}
我想實現在瓦拉是這樣的:
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
}
}
如何寫在瓦拉prepare()
和INDICATE_SPECIAL_CASE
的約束力?
是否有可能將變量分成兩部分?
即使out
變量在調用prepare()
(在execute()
)後寫入,是否可以避免使用指針?