Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

C++11: struct timeval

Tags:

c++

c++11

I was told to not include the C headers like <stdio.h> in a c++ program, but to use <cstdio> etc. instead. How do I get struct timeval without including <sys/time.h>?

Alternative question, is there any C++11 alternative to using select/poll (on a POSIX system)?

like image 299
Jo So Avatar asked Jan 12 '23 14:01

Jo So


1 Answers

The <cstdio> and similar are C++ variants for the C standard library. <sys/time.h> is not part of the C standard library at all (it is part of the POSIX interface for certan OS's), so there is no such thing as a C++ specific sys/ctime, so no, you just have to use the same header-file as in C.

The main reason for having a C style and C++ style header is to apply the extern "C" to the functions declared in the headerfile. In some systems, it may be required to wrap the function like this:

 extern "C" {
 #include <sys/time.h>
 }

but in my Linux system, it does that in the standard <sys/time.h> file.

like image 125
Mats Petersson Avatar answered Jan 16 '23 02:01

Mats Petersson