0

我确实调试了这段代码:

result = conn_process(conn, 1, 0);
if (result == CG_ERR_OK) continue;
if (result == CG_ERR_TIMEOUT)
{
    break;   // i'm here!
}

正如我在调试器中一样,break;我认为这result == CG_ERR_TIMEOUT是真的。在当地人中,我确实看到:

    result  131075  unsigned int

在 Watch 我确实看到:

    CG_ERR_TIMEOUT  error: identifier 'CG_ERR_TIMEOUT' out of scope 

去定义向我展示了这样的代码:

enum {
CG_ERR_OK = 0,
CG_ERR_INTERNAL = CG_RANGE_BEGIN,
CG_ERR_INVALIDARGUMENT,
CG_ERR_UNSUPPORTED,
CG_ERR_TIMEOUT,
CG_ERR_MORE,
CG_ERR_INCORRECTSTATE,
CG_ERR_DUPLICATEID,
CG_ERR_BUFFERTOOSMALL,
CG_ERR_OVERFLOW,
CG_ERR_UNDERFLOW,
CG_RANGE_END
};

所以我只是想知道为什么 CG_ERR_TIMEOUT == 131075。多么奇怪的神奇数字?

4

1 回答 1

5

Because CG_RANGE_BEGIN is 131072 (which is 0x20000).

enum {

    CG_ERR_OK = 0,
    CG_ERR_INTERNAL = CG_RANGE_BEGIN,   // == 131072

From now on every enum value is the previous one plus 1:

    CG_ERR_INVALIDARGUMENT,             // == 131072 + 1 = 131073
    CG_ERR_UNSUPPORTED,                 // == 131073 + 1 = 131074
    CG_ERR_TIMEOUT,                     // == 131074 + 1 = 131075
    CG_ERR_MORE,                        // etc.
    CG_ERR_INCORRECTSTATE,
    CG_ERR_DUPLICATEID,
    CG_ERR_BUFFERTOOSMALL,
    CG_ERR_OVERFLOW,
    CG_ERR_UNDERFLOW,
    CG_RANGE_END

};
于 2012-11-26T14:28:23.220 回答