[comp.unix.aux] include file syntax errors?

cwilson@NISC.SRI.COM (Chan Wilson [Animal]) (10/18/90)

I'm trying to port some fairly tame programs we've developed here, and 
keep running into a include file syntax errors!  There's more than
one; /usr/include/utmp.h springs to mind, but I seen to recall file.h
having problems also.  

This happens under both cc and gcc; even happens if I do a simple:

#include <utmp.h>
main () {}

type of program.   Is this global, is there a fix, or is my computer
hating me this week? :(

Hm.. if it matters, the A/UX dist. was off tape...

--Chan

Chan Wilson                                  Chief Hard-Question Answer Person
SRI Intl. Network Information Systems Center
333 Ravenswood Ave., EJ287			Internet: cwilson@nisc.sri.com
Menlo Park, CA., 94025				Phone: (415)859-4492
    "If I want to be a surfer this month, I bloody well will be."

rmtodd@servalan.uucp (Richard Todd) (10/18/90)

cwilson@NISC.SRI.COM (Chan Wilson [Animal]) writes:
>I'm trying to port some fairly tame programs we've developed here, and 
>keep running into a include file syntax errors!  There's more than
>one; /usr/include/utmp.h springs to mind, but I seen to recall file.h
>having problems also.  

  Nope, this isn't a syntax error in the include file, it's an error in your
program.  Let's take a look at what happens when I try to compile the sample
program you posted:

	21 servalan /tmp[6:43pm] % cat >foo.c
	#include <utmp.h>
	main() {}
	22 servalan /tmp[6:43pm] % gcc foo.c
	In file included from foo.c:1:
	/usr/include/utmp.h:40: parse error before `time_t'
Looking at utmp.h, one notes that the file uses a typedef'd type, time_t,
but does not have the definition for time_t.  The definition for that, along
with a lot of other special types, is found in /usr/include/sys/types.h.
Thus one should #include <sys/types.h> before #include-ing <utmp.h>, viz.:

	26 servalan /tmp[6:49pm] % cat >foo.c
	#include <sys/types.h>
	#include <utmp.h>
	main() {}
	27 servalan /tmp[6:50pm] % gcc foo.c
	28 servalan /tmp[6:50pm] %

Look, Ma, no errors.  
--
Richard Todd	rmtodd@uokmax.ecn.uoknor.edu  rmtodd@chinet.chi.il.us
	rmtodd@servalan.uucp
Motorola Skates On Intel's Head!

gee@dretor.dciem.dnd.ca (Thomas Gee) (10/18/90)

In article <22427@fs2.NISC.SRI.COM> cwilson@NISC.SRI.COM (Chan Wilson [Animal]) writes:
>
>I'm trying to port some fairly tame programs we've developed here, and 
>keep running into a include file syntax errors!

It is not terribly unusual (although it can be terribly frustrating) for
include files to have dependencies on other include files.  In the particular
case you gave (utmp.h), you must include <sys/types.h> before including the
utmp library.

BTW: I did a "man utmp", which brought up the getut(3C) man page, which gives
this information.

>Chan Wilson                                  Chief Hard-Question Answer Person
>SRI Intl. Network Information Systems Center
>333 Ravenswood Ave., EJ287			Internet: cwilson@nisc.sri.com
>Menlo Park, CA., 94025				Phone: (415)859-4492
>    "If I want to be a surfer this month, I bloody well will be."

Tom.

-------------------------------------------------------------------------------
Thomas Gee       |
Aerospace Group  | a man in search of a quote
DCIEM, DND       |
Canada           | gee@dretor.dciem.dnd.ca
-------------------------------------------------------------------------------