tags:

views:

316

answers:

2

I got the error

from error.c:31:
/usr/include/ap/mas.h:254: error: expected specifier-qualifier-list before ‘time_t’
make: *** [error.o] Error 1

Feedback

We at least need to see line 31 of error.c and line 254 of mas.h, with preferably a few lines of context around each. This error may have nothing to do with how time_t is being declared. – John Bode

Then I check in error.c (line no 31) -- #include "mas.h" then I check line no 254 in mas.h.

in mas.h

#include <sys/types.h>
typedef struct _x{
  time_t time;
}x;

Can anybody suggest where I am going wrong?

+4  A: 

Have you #included <time.h>?

sth
In time.h, you can get# include <bits/types.h> /* This defines __time_t for us. */
ambika
@ambika: If that defines `__time_t` that doesn't mean it defines `time_t` as well. The error sounds like `time_t` is not defined. Why do you want to include some internal, implementation specific header?
sth
Also: Are you sure you even include `bits/types.h`? Else it doesn't help if `time_t` is defined there.
sth
Including `<time.h>` before including `"mas.h"` should do the trick, though if the OP can legitimately modify `mas.h`, it should be revised so that it can be used free-standing (it should include `<time.h>` itself to ensure that it compiles correctly).
Jonathan Leffler
hi sth,thanks for your suggestion.i already include #include <sys/types.h>. then also i get error.
ambika
`sys/types.h` is not the same as `bits/types.h` - and *more importantly*, you shouldn't include `bits/types.h`. If you want to use `time_t`, you have to include `time.h`. Simple.
Alok
ambika: Just include time.h; it will include any system-specific files (bits/types.h or sys/types.h) that it needs.
John Bode
A: 

You need to include time.h before including mas.h.

qrdl
No, if mas.h needs something from time.h, then mas.h should be including time.h itself.
Roger Pate
@Roger I guess you don't know how C preprocessor works. It doesn't matter if `time.h` included from `mas.h` (somewhere before the first use of `time_t` type) or before `mas.h` - it will produce the same effect. However there is a school of though (which I'm not completely support) that headers shouldn't be included from headers, but only from main source.
qrdl
Although you are correct, qrdl, that it doesn't matter how time.h is included as long as it is included, Roger is making a serious point. You should be able to include a header and have it work without any other dependencies - so it should be possible to include 'mas.h' without including anything else. And it should compile. See the NASA Goddard Space Flight Center (GSFC) coding standards for a discussion - there are numerous SO questions that cover the ground (including http://stackoverflow.com/questions/1804486/).
Jonathan Leffler