如何定义一个函数

时间:2009-04-14 13:14:25

标签: c objective-c

我想定义以下功能:

    if(stmtToFinalize) {
        NSLog(@"Finalizing statement stmtToFinalize");
        if (sqlite3_finalize(stmtToFinalize) !=SQLITE_OK)
            NSLog(@"An error occured while trying to finalize a statement stmtToFinalize: '%s'", sqlite3_errmsg(database));
        stmtToFinalize = NULL;
    }

但我不熟悉#define指令。我希望代替stmtToFinalize来获得类型为sqlite3_stmt的任何语句。

我该如何实施?

谢谢。

1 个答案:

答案 0 :(得分:2)

#define的语法不是特定于Objective-C的。

#define MY_FUNCTION(x) do { \
    if( (x) ) { \
        NSLog(@"Finalizing statement stmtToFinalize"); \
        if (sqlite3_finalize( (x) ) !=SQLITE_OK) \
                NSLog(@"An error occured while trying to finalize a statement stmtToFinalize: '%s'", sqlite3_errmsg(database)); \
        (x) = NULL; \
    } } while (0)

NSLog()格式字符串中的文本尚未更改。