什么是转换的正确方法/施放一个int
在C99一size_t
上32位和64位Linux平台?C:投INT为size_t
实施例:
int hash(void * key) {
//...
}
int main (int argc, char * argv[]) {
size_t size = 10;
void * items[size];
//...
void * key = ...;
// Is this the right way to convert the returned int from the hash function
// to a size_t?
size_t key_index = (size_t)hash(key) % size;
void * item = items[key_index];
}
我不明白为什么这是行不通的。 – slartibartfast 2011-03-30 02:01:54
什么是与一般的普通铸铁'(为size_t)'的问题吗?它有点不合适吗? – AnT 2011-03-30 02:02:32
是啊,这是正确的,但我认为这是隐式转换,所以你不会真的* *需要'(为size_t)'。 – 2011-03-30 02:02:38