Steve Ellcey
2017-10-18 21:16:18 UTC
I have a question about who defines timespec, time.h or sys/time.h.
I am trying to build blender (which is part of SPEC 2017) and
it has a file, blender/source/blender/blenlib/intern/threads.c,
that basically has:
#include <sys/time.h>
int foo(struct timespec *timeout)
{
return (timeout->tv_sec);
}
If I use my installed compiler (gcc 5.4, libc 2.23) and compile with
-std=c11, this works fine. If I use top-of-tree GCC and GLIBC and
-std=c11, I get this:
x.c:2:16: warning: ‘struct timespec’ declared inside parameter list will not be visible outside of this definition or declaration
int foo(struct timespec *timeout)
^~~~~~~~
x.c: In function ‘foo’:
x.c:4:17: error: dereferencing pointer to incomplete type ‘struct timespec’
return (timeout->tv_sec);
It looks like the older sys/time.h would include time.h but the current one
doesn't. Is this change intentional? I am guessing it is. Does the ISO C11
standard says that you need to include time.h and not sys/time.h to get
the timespec structure? I don't have a copy of the standard but that would
seem to be the implication of this code in the current time.h:
#if defined __USE_POSIX199309 || defined __USE_ISOC11
# include <bits/types/struct_timespec.h>
#endif
Should I (we, if anyone already has contacts) try to get the blender/SPEC code
changed? I know that I can work around this with -std=gnu99 or -std=gnu11
but I would rather not have to do that and if the code is not correct (for some
definition of correct) I think we should try to get it fixed rather than work
around it.
Steve Ellcey
***@cavium.com
I am trying to build blender (which is part of SPEC 2017) and
it has a file, blender/source/blender/blenlib/intern/threads.c,
that basically has:
#include <sys/time.h>
int foo(struct timespec *timeout)
{
return (timeout->tv_sec);
}
If I use my installed compiler (gcc 5.4, libc 2.23) and compile with
-std=c11, this works fine. If I use top-of-tree GCC and GLIBC and
-std=c11, I get this:
x.c:2:16: warning: ‘struct timespec’ declared inside parameter list will not be visible outside of this definition or declaration
int foo(struct timespec *timeout)
^~~~~~~~
x.c: In function ‘foo’:
x.c:4:17: error: dereferencing pointer to incomplete type ‘struct timespec’
return (timeout->tv_sec);
It looks like the older sys/time.h would include time.h but the current one
doesn't. Is this change intentional? I am guessing it is. Does the ISO C11
standard says that you need to include time.h and not sys/time.h to get
the timespec structure? I don't have a copy of the standard but that would
seem to be the implication of this code in the current time.h:
#if defined __USE_POSIX199309 || defined __USE_ISOC11
# include <bits/types/struct_timespec.h>
#endif
Should I (we, if anyone already has contacts) try to get the blender/SPEC code
changed? I know that I can work around this with -std=gnu99 or -std=gnu11
but I would rather not have to do that and if the code is not correct (for some
definition of correct) I think we should try to get it fixed rather than work
around it.
Steve Ellcey
***@cavium.com