time.h and sys/time.h

In QNX4, sys/time.h includes time.h and time.h defines:

struct timespec {
long tv_sec,
tv_nsec;
};

struct itimerspec {
struct timespec it_value,
it_interval;
int notify_type,
timer_type;
long data;
};

but in QRTP, it doesn’t look like sys/time.h includes time.h, and time.h
doesn’t define timespec anymore, although it uses it:


struct itimerspec {
struct timespec it_value,
it_interval;
};

where is timespec defined now? I’ve seen it defined in other headers
files like mqueue.h as simply:

struct timespec;

How does that work?

Scott

It’s in /usr/include/sys/target_nto.h

J. Scott Franko <jsfranko@switch.com> wrote:

In QNX4, sys/time.h includes time.h and time.h defines:

struct timespec {
long tv_sec,
tv_nsec;
};

struct itimerspec {
struct timespec it_value,
it_interval;
int notify_type,
timer_type;
long data;
};

but in QRTP, it doesn’t look like sys/time.h includes time.h, and time.h
doesn’t define timespec anymore, although it uses it:



struct itimerspec {
struct timespec it_value,
it_interval;
};

where is timespec defined now? I’ve seen it defined in other headers
files like mqueue.h as simply:

struct timespec;

How does that work?

Scott


cburgess@qnx.com

How portable is that? How should I use it. Is there some convention for
using it? Is that in the docs somewhere?

Scott

Colin Burgess wrote:

It’s in /usr/include/sys/target_nto.h

J. Scott Franko <> jsfranko@switch.com> > wrote:
In QNX4, sys/time.h includes time.h and time.h defines:

struct timespec {
long tv_sec,
tv_nsec;
};

struct itimerspec {
struct timespec it_value,
it_interval;
int notify_type,
timer_type;
long data;
};

but in QRTP, it doesn’t look like sys/time.h includes time.h, and time.h
doesn’t define timespec anymore, although it uses it:

struct itimerspec {
struct timespec it_value,
it_interval;
};

where is timespec defined now? I’ve seen it defined in other headers
files like mqueue.h as simply:

struct timespec;

How does that work?

Scott


cburgess@qnx.com

Well, target_nto.h is actually included by sys/platform.h, which is
included by a lot of different headers, notably sys/types.h

J. Scott Franko <jsfranko@switch.com> wrote:

How portable is that? How should I use it. Is there some convention for
using it? Is that in the docs somewhere?

Scott

Colin Burgess wrote:

It’s in /usr/include/sys/target_nto.h

J. Scott Franko <> jsfranko@switch.com> > wrote:
In QNX4, sys/time.h includes time.h and time.h defines:

struct timespec {
long tv_sec,
tv_nsec;
};

struct itimerspec {
struct timespec it_value,
it_interval;
int notify_type,
timer_type;
long data;
};

but in QRTP, it doesn’t look like sys/time.h includes time.h, and time.h
doesn’t define timespec anymore, although it uses it:

struct itimerspec {
struct timespec it_value,
it_interval;
};

where is timespec defined now? I’ve seen it defined in other headers
files like mqueue.h as simply:

struct timespec;

How does that work?

Scott


cburgess@qnx.com


cburgess@qnx.com

Colin Burgess <cburgess@qnx.com> wrote:

Well, target_nto.h is actually included by sys/platform.h, which is
included by a lot of different headers, notably sys/types.h

In fact it’s included by time.h as well. :slight_smile:

J. Scott Franko <> jsfranko@switch.com> > wrote:
How portable is that? How should I use it. Is there some convention for
using it? Is that in the docs somewhere?

Scott

Colin Burgess wrote:

It’s in /usr/include/sys/target_nto.h

J. Scott Franko <> jsfranko@switch.com> > wrote:
In QNX4, sys/time.h includes time.h and time.h defines:

struct timespec {
long tv_sec,
tv_nsec;
};

struct itimerspec {
struct timespec it_value,
it_interval;
int notify_type,
timer_type;
long data;
};

but in QRTP, it doesn’t look like sys/time.h includes time.h, and time.h
doesn’t define timespec anymore, although it uses it:

struct itimerspec {
struct timespec it_value,
it_interval;
};

where is timespec defined now? I’ve seen it defined in other headers
files like mqueue.h as simply:

struct timespec;

How does that work?

Scott


cburgess@qnx.com


cburgess@qnx.com


cburgess@qnx.com

Yes, I guess I was going down the wrong track to solve a warning. I can’t find a
description of the warnings anywhere. I’ve tried the gcc pages on the web, I’ve
tired helpviewer.

I get this warning about a variable of ours called waittime declared in one of our
header files. It has an initializer and is defined like this:

static struct timespec waittime = {0, 40*100000);

The warning say’s something like , variable ‘waittime’ has an initializer but has
incomplete type.

I thought maybe it was trouble with a changed definition of timespec, but its the
same.

Forgive my nubee questions, but I’m just starting to really get involved with the
wild world of open source c programming. GNU is GNU to me! ;O)

Scott

Colin Burgess wrote:

Colin Burgess <> cburgess@qnx.com> > wrote:
Well, target_nto.h is actually included by sys/platform.h, which is
included by a lot of different headers, notably sys/types.h

In fact it’s included by time.h as well. > :slight_smile:

J. Scott Franko <> jsfranko@switch.com> > wrote:
How portable is that? How should I use it. Is there some convention for
using it? Is that in the docs somewhere?

Scott

Colin Burgess wrote:

It’s in /usr/include/sys/target_nto.h

J. Scott Franko <> jsfranko@switch.com> > wrote:
In QNX4, sys/time.h includes time.h and time.h defines:

struct timespec {
long tv_sec,
tv_nsec;
};

struct itimerspec {
struct timespec it_value,
it_interval;
int notify_type,
timer_type;
long data;
};

but in QRTP, it doesn’t look like sys/time.h includes time.h, and time.h
doesn’t define timespec anymore, although it uses it:

struct itimerspec {
struct timespec it_value,
it_interval;
};

where is timespec defined now? I’ve seen it defined in other headers
files like mqueue.h as simply:

struct timespec;

How does that work?

Scott


cburgess@qnx.com


cburgess@qnx.com


cburgess@qnx.com

I tried

#include <time.h>

static struct timespec waittime = {0, 40*100000};

and had no comiple errors.

Are you sure you’re including time.h before your declaration of waittime?

J. Scott Franko <jsfranko@switch.com> wrote:

Yes, I guess I was going down the wrong track to solve a warning. I can’t find a
description of the warnings anywhere. I’ve tried the gcc pages on the web, I’ve
tired helpviewer.

I get this warning about a variable of ours called waittime declared in one of our
header files. It has an initializer and is defined like this:

static struct timespec waittime = {0, 40*100000);

The warning say’s something like , variable ‘waittime’ has an initializer but has
incomplete type.

I thought maybe it was trouble with a changed definition of timespec, but its the
same.

Forgive my nubee questions, but I’m just starting to really get involved with the
wild world of open source c programming. GNU is GNU to me! ;O)

Scott

Colin Burgess wrote:

Colin Burgess <> cburgess@qnx.com> > wrote:
Well, target_nto.h is actually included by sys/platform.h, which is
included by a lot of different headers, notably sys/types.h

In fact it’s included by time.h as well. > :slight_smile:

J. Scott Franko <> jsfranko@switch.com> > wrote:
How portable is that? How should I use it. Is there some convention for
using it? Is that in the docs somewhere?

Scott

Colin Burgess wrote:

It’s in /usr/include/sys/target_nto.h

J. Scott Franko <> jsfranko@switch.com> > wrote:
In QNX4, sys/time.h includes time.h and time.h defines:

struct timespec {
long tv_sec,
tv_nsec;
};

struct itimerspec {
struct timespec it_value,
it_interval;
int notify_type,
timer_type;
long data;
};

but in QRTP, it doesn’t look like sys/time.h includes time.h, and time.h
doesn’t define timespec anymore, although it uses it:

struct itimerspec {
struct timespec it_value,
it_interval;
};

where is timespec defined now? I’ve seen it defined in other headers
files like mqueue.h as simply:

struct timespec;

How does that work?

Scott


cburgess@qnx.com


cburgess@qnx.com


cburgess@qnx.com


cburgess@qnx.com

Colin Burgess wrote:

I tried

#include <time.h

static struct timespec waittime = {0, 40*100000};

and had no comiple errors.

Try putting the above in a .h file, and then include that in a small c file and put in
the macros below, and use them in the in the test function and compile that. It works
on QNX4, but not on NTO.

#define wait_40ms() nanosleep(&waittime, 0);
#define WAIT_40MS() nanosleep(&waittime,0);

When I remove the initializer, NTO lets things compile, but of course that screws the
40ms wait for the macro.

Scott

Are you sure you’re including time.h before your declaration of waittime?

J. Scott Franko <> jsfranko@switch.com> > wrote:
Yes, I guess I was going down the wrong track to solve a warning. I can’t find a
description of the warnings anywhere. I’ve tried the gcc pages on the web, I’ve
tired helpviewer.

I get this warning about a variable of ours called waittime declared in one of our
header files. It has an initializer and is defined like this:

static struct timespec waittime = {0, 40*100000);

The warning say’s something like , variable ‘waittime’ has an initializer but has
incomplete type.

I thought maybe it was trouble with a changed definition of timespec, but its the
same.

Forgive my nubee questions, but I’m just starting to really get involved with the
wild world of open source c programming. GNU is GNU to me! ;O)

Scott

Colin Burgess wrote:

Colin Burgess <> cburgess@qnx.com> > wrote:
Well, target_nto.h is actually included by sys/platform.h, which is
included by a lot of different headers, notably sys/types.h

In fact it’s included by time.h as well. > :slight_smile:

J. Scott Franko <> jsfranko@switch.com> > wrote:
How portable is that? How should I use it. Is there some convention for
using it? Is that in the docs somewhere?

Scott

Colin Burgess wrote:

It’s in /usr/include/sys/target_nto.h

J. Scott Franko <> jsfranko@switch.com> > wrote:
In QNX4, sys/time.h includes time.h and time.h defines:

struct timespec {
long tv_sec,
tv_nsec;
};

struct itimerspec {
struct timespec it_value,
it_interval;
int notify_type,
timer_type;
long data;
};

but in QRTP, it doesn’t look like sys/time.h includes time.h, and time.h
doesn’t define timespec anymore, although it uses it:

struct itimerspec {
struct timespec it_value,
it_interval;
};

where is timespec defined now? I’ve seen it defined in other headers
files like mqueue.h as simply:

struct timespec;

How does that work?

Scott


cburgess@qnx.com


cburgess@qnx.com


cburgess@qnx.com


cburgess@qnx.com

Ok, here’s what I tried…

–waittime.h------------------------------------------------------

#include <time.h>
static struct timespec waittime = {0, 40*100000};

–waittime.c------------------------------------------------------
#include “waittime.h”

#define wait_40ms() nanosleep(&waittime, 0);
#define WAIT_40MS() nanosleep(&waittime,0);

int main(void)
{
wait_40ms();

return 0;
}


This compiled with no errors, and ran. Can you post me your
example that doesn’t work?

J. Scott Franko <jsfranko@switch.com> wrote:


Colin Burgess wrote:

I tried

#include <time.h

static struct timespec waittime = {0, 40*100000};

and had no comiple errors.

Try putting the above in a .h file, and then include that in a small c file and put in
the macros below, and use them in the in the test function and compile that. It works
on QNX4, but not on NTO.

#define wait_40ms() nanosleep(&waittime, 0);
#define WAIT_40MS() nanosleep(&waittime,0);

When I remove the initializer, NTO lets things compile, but of course that screws the
40ms wait for the macro.

Scott



Are you sure you’re including time.h before your declaration of waittime?

J. Scott Franko <> jsfranko@switch.com> > wrote:
Yes, I guess I was going down the wrong track to solve a warning. I can’t find a
description of the warnings anywhere. I’ve tried the gcc pages on the web, I’ve
tired helpviewer.

I get this warning about a variable of ours called waittime declared in one of our
header files. It has an initializer and is defined like this:

static struct timespec waittime = {0, 40*100000);

The warning say’s something like , variable ‘waittime’ has an initializer but has
incomplete type.

I thought maybe it was trouble with a changed definition of timespec, but its the
same.

Forgive my nubee questions, but I’m just starting to really get involved with the
wild world of open source c programming. GNU is GNU to me! ;O)

Scott

Colin Burgess wrote:

Colin Burgess <> cburgess@qnx.com> > wrote:
Well, target_nto.h is actually included by sys/platform.h, which is
included by a lot of different headers, notably sys/types.h

In fact it’s included by time.h as well. > :slight_smile:

J. Scott Franko <> jsfranko@switch.com> > wrote:
How portable is that? How should I use it. Is there some convention for
using it? Is that in the docs somewhere?

Scott

Colin Burgess wrote:

It’s in /usr/include/sys/target_nto.h

J. Scott Franko <> jsfranko@switch.com> > wrote:
In QNX4, sys/time.h includes time.h and time.h defines:

struct timespec {
long tv_sec,
tv_nsec;
};

struct itimerspec {
struct timespec it_value,
it_interval;
int notify_type,
timer_type;
long data;
};

but in QRTP, it doesn’t look like sys/time.h includes time.h, and time.h
doesn’t define timespec anymore, although it uses it:

struct itimerspec {
struct timespec it_value,
it_interval;
};

where is timespec defined now? I’ve seen it defined in other headers
files like mqueue.h as simply:

struct timespec;

How does that work?

Scott


cburgess@qnx.com


cburgess@qnx.com


cburgess@qnx.com


cburgess@qnx.com


cburgess@qnx.com

change #include <time.h> to #include <sys/time.h>. That produces the bug. Also your
40100000 should be 401000000 (missing a zero) but that’s just a matter of time, and really
has no relation to this problem.

Why, if <sys/time.h> indirectly includes <time.h>, does this produce a problem? What does
the bug mean? But that solves my problem. I just changed my include to <time.h> instead
of <sys/time.h> and it compiled ok. I thought I had tried that but I guess not.

Scott

Colin Burgess wrote:

Ok, here’s what I tried…

–waittime.h------------------------------------------------------

#include <time.h
static struct timespec waittime = {0, 40*100000};

–waittime.c------------------------------------------------------
#include “waittime.h”

#define wait_40ms() nanosleep(&waittime, 0);
#define WAIT_40MS() nanosleep(&waittime,0);

int main(void)
{
wait_40ms();

return 0;
}


This compiled with no errors, and ran. Can you post me your
example that doesn’t work?

J. Scott Franko <> jsfranko@switch.com> > wrote:

Colin Burgess wrote:

I tried

#include <time.h

static struct timespec waittime = {0, 40*100000};

and had no comiple errors.

Try putting the above in a .h file, and then include that in a small c file and put in
the macros below, and use them in the in the test function and compile that. It works
on QNX4, but not on NTO.

#define wait_40ms() nanosleep(&waittime, 0);
#define WAIT_40MS() nanosleep(&waittime,0);

When I remove the initializer, NTO lets things compile, but of course that screws the
40ms wait for the macro.

Scott



Are you sure you’re including time.h before your declaration of waittime?

J. Scott Franko <> jsfranko@switch.com> > wrote:
Yes, I guess I was going down the wrong track to solve a warning. I can’t find a
description of the warnings anywhere. I’ve tried the gcc pages on the web, I’ve
tired helpviewer.

I get this warning about a variable of ours called waittime declared in one of our
header files. It has an initializer and is defined like this:

static struct timespec waittime = {0, 40*100000);

The warning say’s something like , variable ‘waittime’ has an initializer but has
incomplete type.

I thought maybe it was trouble with a changed definition of timespec, but its the
same.

Forgive my nubee questions, but I’m just starting to really get involved with the
wild world of open source c programming. GNU is GNU to me! ;O)

Scott

Colin Burgess wrote:

Colin Burgess <> cburgess@qnx.com> > wrote:
Well, target_nto.h is actually included by sys/platform.h, which is
included by a lot of different headers, notably sys/types.h

In fact it’s included by time.h as well. > :slight_smile:

J. Scott Franko <> jsfranko@switch.com> > wrote:
How portable is that? How should I use it. Is there some convention for
using it? Is that in the docs somewhere?

Scott

Colin Burgess wrote:

It’s in /usr/include/sys/target_nto.h

J. Scott Franko <> jsfranko@switch.com> > wrote:
In QNX4, sys/time.h includes time.h and time.h defines:

struct timespec {
long tv_sec,
tv_nsec;
};

struct itimerspec {
struct timespec it_value,
it_interval;
int notify_type,
timer_type;
long data;
};

but in QRTP, it doesn’t look like sys/time.h includes time.h, and time.h
doesn’t define timespec anymore, although it uses it:

struct itimerspec {
struct timespec it_value,
it_interval;
};

where is timespec defined now? I’ve seen it defined in other headers
files like mqueue.h as simply:

struct timespec;

How does that work?

Scott


cburgess@qnx.com


cburgess@qnx.com


cburgess@qnx.com


cburgess@qnx.com


cburgess@qnx.com

Ah, mystery solved.

/usr/include/sys/target_nto.h doesn’t actually define struct timespec.
It just sets up a preprocessor define for it. It’s actually used to
define it in /usr/include/time.h, so that’s why you need it.

/usr/include/sys/time.h doesn’t end up including time.h

J. Scott Franko <jsfranko@switch.com> wrote:

change #include <time.h> to #include <sys/time.h>. That produces the bug. Also your
40100000 should be 401000000 (missing a zero) but that’s just a matter of time, and really
has no relation to this problem.

Why, if <sys/time.h> indirectly includes <time.h>, does this produce a problem? What does
the bug mean? But that solves my problem. I just changed my include to <time.h> instead
of <sys/time.h> and it compiled ok. I thought I had tried that but I guess not.

Scott

Colin Burgess wrote:

Ok, here’s what I tried…

–waittime.h------------------------------------------------------

#include <time.h
static struct timespec waittime = {0, 40*100000};

–waittime.c------------------------------------------------------
#include “waittime.h”

#define wait_40ms() nanosleep(&waittime, 0);
#define WAIT_40MS() nanosleep(&waittime,0);

int main(void)
{
wait_40ms();

return 0;
}


This compiled with no errors, and ran. Can you post me your
example that doesn’t work?

J. Scott Franko <> jsfranko@switch.com> > wrote:

Colin Burgess wrote:

I tried

#include <time.h

static struct timespec waittime = {0, 40*100000};

and had no comiple errors.

Try putting the above in a .h file, and then include that in a small c file and put in
the macros below, and use them in the in the test function and compile that. It works
on QNX4, but not on NTO.

#define wait_40ms() nanosleep(&waittime, 0);
#define WAIT_40MS() nanosleep(&waittime,0);

When I remove the initializer, NTO lets things compile, but of course that screws the
40ms wait for the macro.

Scott



Are you sure you’re including time.h before your declaration of waittime?

J. Scott Franko <> jsfranko@switch.com> > wrote:
Yes, I guess I was going down the wrong track to solve a warning. I can’t find a
description of the warnings anywhere. I’ve tried the gcc pages on the web, I’ve
tired helpviewer.

I get this warning about a variable of ours called waittime declared in one of our
header files. It has an initializer and is defined like this:

static struct timespec waittime = {0, 40*100000);

The warning say’s something like , variable ‘waittime’ has an initializer but has
incomplete type.

I thought maybe it was trouble with a changed definition of timespec, but its the
same.

Forgive my nubee questions, but I’m just starting to really get involved with the
wild world of open source c programming. GNU is GNU to me! ;O)

Scott

Colin Burgess wrote:

Colin Burgess <> cburgess@qnx.com> > wrote:
Well, target_nto.h is actually included by sys/platform.h, which is
included by a lot of different headers, notably sys/types.h

In fact it’s included by time.h as well. > :slight_smile:

J. Scott Franko <> jsfranko@switch.com> > wrote:
How portable is that? How should I use it. Is there some convention for
using it? Is that in the docs somewhere?

Scott

Colin Burgess wrote:

It’s in /usr/include/sys/target_nto.h

J. Scott Franko <> jsfranko@switch.com> > wrote:
In QNX4, sys/time.h includes time.h and time.h defines:

struct timespec {
long tv_sec,
tv_nsec;
};

struct itimerspec {
struct timespec it_value,
it_interval;
int notify_type,
timer_type;
long data;
};

but in QRTP, it doesn’t look like sys/time.h includes time.h, and time.h
doesn’t define timespec anymore, although it uses it:

struct itimerspec {
struct timespec it_value,
it_interval;
};

where is timespec defined now? I’ve seen it defined in other headers
files like mqueue.h as simply:

struct timespec;

How does that work?

Scott


cburgess@qnx.com


cburgess@qnx.com


cburgess@qnx.com


cburgess@qnx.com


cburgess@qnx.com


cburgess@qnx.com