¿Cuál es la forma correcta de convertir/emitir un int
a un size_t
en C99 en plataformas de 32 bits y 64 bits de Linux?C: fundido int a size_t
Ejemplo:
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];
}
no veo razón por la que no funcionaría. – slartibartfast
¿Cuál es el problema con un molde común ordinario '(size_t)'? ¿De alguna manera no es "apropiado"? – AnT
Sí, eso es correcto, aunque creo que está convertido implícitamente por lo que no * realmente * necesita el '(size_t)'. –