🚀 go-pugleaf

RetroBBS NetNews Server

Inspired by RockSolid Light RIP Retro Guy

Article View: gwu.seas
Article #3

Re: help: gcc

#3
From: Kurt Watzka
Date: Mon, 11 Mar 1996 16:07
94 lines
3461 bytes
Matthias Dittrich <matti> writes:

>spiffy@seas.gwu.edu (Marc Goldberg) wrote:
>>
>>Trying to compile a program on Solaris 2.5, I've removed all bugs (syntax 
>>errors, at least) but these.  Any help would be *greatly* appreciated.
>>
>>Thanks,
>>--Marc
>>
>>~~~~~
>>spiffy@felix:5: gcc 2FarmCheck.c 
>>2FarmCheck.c: In function `readHostFiles':
>>2FarmCheck.c:23: dereferencing pointer to incomplete type
>>2FarmCheck.c:25: dereferencing pointer to incomplete type
>>2FarmCheck.c:27: warning: passing arg 3 of `fgets' from incompatible 
>>		 pointer type
>>2FarmCheck.c: In function `main':
>>2FarmCheck.c:66: storage size of `PID' isn't known
>>~~~~~~
>>
>>The lines referred to are:
>>
>>char *readHostFiles(char *name)
>>      {
>>      int foo;
>>      struct FILE *fileDisc;

FILE _is_ a "struct _iobuf" or something similar in most implementations.
So, struct FILE is an incomplete type, and is _not_ related to FILE,
because struct "tags" and typedefed names live in different namespaces.

>>
>>(23)  *fileDisc = fopen("/users/spiffy/urls.txt", O_RDONLY);

The function fopen()  I know returns a "FILE *". So, if fileDisc would
be defined as "FILE *fileDisc", no dereferencing would be needed.OTOH,
the function I know takes a "const char *" as it's second argument,
so maybe we are talking about different functions.

>>
>>(25)  while (!feof(fileDisc))
>>        {
>>(27)      if ( fgets(name, HOSTNAMESIZE, fileDisc) != name)
>>          exit(12);
>>        }

In C, feof() is not endowed with clairvoyance, a simple fgets() would
do all you need to both read a line from the file and find out 
whether you have reached the end of that file.

>>      return name; 
>>      } 
>>|
>>|
>>|
>>int main(void)
>>      {
>>(66)  struct pid_t PID;

This is _very_ system specific, but if you are talking about a
system that is somehow similar to the system I am thinking about
(happens to be Solaris 2.4), a pid_t is certainly not a struct,
but it might have been introduced by something like 

   typedef long pid_t;

Again, "struct pid_t" is an incomplete type that is _not_ related
to the typedef name "pid_t".

>>      char name[HOSTNAMESIZE];        /*Hostname of server to check on*/
>>
>>      PID = getpid();
>>      ...other stuff...
>>      }

>You have to include the header files which are defining the missung types and
>functions. These should be stdio.h for file handling and sys/unistd.h for
>getpid() and pid_t.

I do _not_ agree with this analysis. Without a prototype for fgets()
in scope, the argument type mismatch for that function could not
have been detected.

The main source of the problem seems to be that struct "tags" and
typedefed names do not live in the same namespace, so the compiler
is not able do diagnose the kind of confusion that the original
poster suffers from.

Kurt
--
| Kurt Watzka                             Phone : +49-89-2180-6254
| watzka@stat.uni-muenchen.de
| ua302aa@sunmail.lrz-muenchen.de
Technical Details
Message-ID: <4i1j4d$mpn@sparcserver.lrz-muenchen.de>
Path: arc1-ca.pugleaf.net!lrz-muenchen.de!news
References: <4hpiht$1n2@cronkite.seas.gwu.edu> <4i0l50$js0@hpbblb.bbn.hp.com>

Show Full Headers
Complete Article Headers
Path: arc1-ca.pugleaf.net!lrz-muenchen.de!news
From: watzka@stat.uni-muenchen.de (Kurt Watzka)
Newsgroups: gwu.seas,comp.lang.c
Subject: Re: help: gcc
Date: 11 Mar 1996 16:07:41 GMT
Organization: Leibniz-Rechenzentrum, Muenchen (Germany)
Distribution: world
Message-ID: <4i1j4d$mpn@sparcserver.lrz-muenchen.de>
References: <4hpiht$1n2@cronkite.seas.gwu.edu> <4i0l50$js0@hpbblb.bbn.hp.com>
NNTP-Posting-Host: sun2.lrz-muenchen.de