C ++ 11: struct timeval

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

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

+4
source share
2 answers

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

The main reason for having the C style and C ++ style header is the application of extern "C" to the functions declared in the header file. On some systems, you may need to wrap a function as follows:

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

but on my Linux system this is done in the standard <sys/time.h> file.

+9
source

<cstdio> is C ++ - a variant of the C <stdio.h> library. The difference is that C versions are defined in the global namespace.

You can see a list of these headers here: http://www.cplusplus.com/reference/clibrary/

<sys/time.h> not part of the standard library, so there is no equivalent in C ++. You just need to use it, as in C.

0
source

Source: https://habr.com/ru/post/1497873/


All Articles