Question

I am using timeval structure in order to get current system time. Normally if I declare it like that:

timeval curtime;

it is working. However I saw some code where people declare it as:

struct timeval curtime;

Is there any difference between these two?

Was it helpful?

Solution

In C, you must use struct prefix when declaring a variable with a struct type.

In C++, it's not required to prefix with struct.

Since you have tagged this as a C++ question, I assume you are using a C++ compiler and so you do not get a compiler error when you use timeval without the struct prefix. However, if you were to use a C compiler, it would issue an error.

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top