I was going through some code when I encountered this in one of the source files.
int st_insert(table, key, value)
register st_table *table;
register st_data_t key;
st_data_t value;
{
unsigned int hash_val, bin_pos;
register st_table_entry *ptr;
hash_val = do_hash(key, table);
FIND_ENTRY(table, ptr, hash_val, bin_pos);
if (ptr == 0) {
ADD_DIRECT(table, key, value, hash_val, bin_pos);
return 0;
} else {
ptr->record = value;
return 1;
}
}
What is this style? Is it some obscure way to declare functions? Is there some reason one might use this over normal function declarations?
register
arguments are still legal in modern C. The compiler is free to ignore it and like will if the ABI does not allow it (or usese registers anyway). – Bosregister
doesn't have anything to do with hardware-registers, only with not taking the address of the object. – Iceregister
was definitively meant to tell the compiler to hold these variables in CPU registers. This just implied you cannot take its address. Just remember when this function definition-style was used (and whenregister
was used for its original purpose). Nowadays, the side-effect is the only reason to use it, because the compiler will allocate CPU registers most times itself often better than the programmer can (although it might still take it as a hint). – Bos