I am fairly new to C and am going over some code to learn about hashing.
I came across a file that contained the following lines of code:
#include <stdio.h>
#include <stdbool.h>
#include <stdint.h>
#include <stdlib.h>
#include <time.h>
#include <sys/time.h>
// ---------------------------------------------------------------------------
int64_t timing(bool start)
{
static struct timeval startw, endw; // What is this?
int64_t usecs = 0;
if(start) {
gettimeofday(&startw, NULL);
}
else {
gettimeofday(&endw, NULL);
usecs =
(endw.tv_sec - startw.tv_sec)*1000000 +
(endw.tv_usec - startw.tv_usec);
}
return usecs;
}
I have never come across a static struct defined in this manner before. Usually a struct is preceded by the definition/declaration of the struct. However, this just seems to state there are going to be static struct variables of type timeval, startw, endw.
I have tried to read up on what this does but have not yet found a good enough explanation. Any help?