I am learning/re-learning C, and I've learnt about the register keyword. On many websites, people said it is recommended to not be used, or even useless. The book I am using says it is useful in for-loops, then I tried without the keyword:
#include <stdio.h>
#include <time.h>
int main() {
int count = 1;
clock_t start = clock();
while(count != 0) {
count++;
}
clock_t stop = clock();
double time = (double)(stop - start);
printf("%f", time);
return 0;
}
and, then with it:
[..] register int count = 1; [...]
Compiling the source code with GCC, I have seen that using register made the program around 5x faster. Executables:
- https://drive.google.com/file/d/1IQHmmNSo6wbAXhl8cBzKjzXLPmvbseQB/view?usp=sharing
- https://drive.google.com/file/d/1MtV_eRoe-WDWNKT48yk1T3jadIm6SuOD/view?usp=sharing
Hence, my question, is there something wrong with me (e.g. my GCC) or is the register keyword actually useful?