[news.software.b] Problem compiling latest C-news under Ultrix 4.1

stealth@engin.umich.edu (Mike Pelletier) (04/04/91)

Having set up the software to use the fast stdio routines, I get the following
error when it attempts to compile them:

/bin/cc '-DPTR_TYPE=unsigned char *' -O -s -c rdwr.c
ccom: Error: rdwr.c, line 20: redeclaration of fread
      int
      fread(ptr, size, count, fp)
      char *ptr;
      ---^
ccom: Error: rdwr.c, line 70: redeclaration of fwrite
      int
      fwrite(ptr, size, count, fp)
      char *ptr;
      ---^
*** Error code 1

Stop.
+ exit 1

Is there any way I can coax the C compiler to accept these new
versions of stdio routines?  Considering the speedup they provide,
I would like to use them if at all possible.

henry@zoo.toronto.edu (Henry Spencer) (04/04/91)

In article <1991Apr3.173459.3081@engin.umich.edu> stealth@engin.umich.edu (Mike Pelletier) writes:
>      char *ptr;
>      ---^
>ccom: Error: rdwr.c, line 70: redeclaration of fwrite

You can try changing those "char *"s to "void *"s, although this will mean
further work within the routines to make it all turn out right.  Not a
trivial fix, I'm afraid.
-- 
"The stories one hears about putting up | Henry Spencer @ U of Toronto Zoology
SunOS 4.1.1 are all true."  -D. Harrison|  henry@zoo.toronto.edu  utzoo!henry

gamiddle@watmath.waterloo.edu (Guy Middleton) (04/04/91)

In article <1991Apr3.190011.1117@zoo.toronto.edu> henry@zoo.toronto.edu (Henry Spencer) writes:
> In article <1991Apr3.173459.3081@engin.umich.edu> stealth@engin.umich.edu (Mike Pelletier) writes:
> >      char *ptr;
> >      ---^
> >ccom: Error: rdwr.c, line 70: redeclaration of fwrite
> 
> You can try changing those "char *"s to "void *"s, although this will mean
> further work within the routines to make it all turn out right.  Not a
> trivial fix, I'm afraid.

Actually, the fix is to change

	int
	fread(ptr, size, count, fp)

to	size_t
	fread(ptr, size, count, fp)

Changing "char *" to "void *" fixes the warnings, but not the errors.

stealth@caen.engin.umich.edu (Mike Pelletier) (04/04/91)

In article <1991Apr4.035820.8952@watmath.waterloo.edu>
	gamiddle@watmath.waterloo.edu (Guy Middleton) writes:
>In article <1991Apr3.190011.1117@zoo.toronto.edu>
	henry@zoo.toronto.edu (Henry Spencer) writes:
>> In article <1991Apr3.173459.3081@engin.umich.edu> I write:
>> >      char *ptr;
>> >      ---^
>> >ccom: Error: rdwr.c, line 70: redeclaration of fwrite
>> 
>> You can try changing those "char *"s to "void *"s, although this will mean
>> further work within the routines to make it all turn out right.  Not a
>> trivial fix, I'm afraid.
>
>Actually, the fix is to change
>
>	int
>	fread(ptr, size, count, fp)
>
>to	size_t
>	fread(ptr, size, count, fp)
>
>Changing "char *" to "void *" fixes the warnings, but not the errors.

Thanks, Guy, that worked perfectly!
I still get two warnings out of that file, namely:

ccom: Warning: rdwr.c, line 44: illegal pointer combination
                                fp->_ptr = (unsigned char *)bp;
      --------------------------------------------------------^
ccom: Warning: rdwr.c, line 93: illegal pointer combination
                                fp->_ptr = (unsigned char *)bp;
      --------------------------------------------------------^

but it does indeed produce a .o file in spite of these complaints.
Why does changing "int" to "size_t" cure this particular problem?
Isn't size_t just typedef'ed to int in one of the include files?

--
Mike Pelletier                     |
The University of Michigan's       |           [this section intentionally]
Computer Aided Engineering Network |           [         left blank       ]
  Usenet, UUCP, IRC and mail admin |

gamiddle@watmath.waterloo.edu (Guy Middleton) (04/05/91)

In article <1991Apr4.150426.25479@engin.umich.edu> stealth@caen.engin.umich.edu (Mike Pelletier) writes:
> Why does changing "int" to "size_t" cure this particular problem?
> Isn't size_t just typedef'ed to int in one of the include files?

It is, but fread() and fwrite() were never declared in <stdio.h> before, and
are now.  They always returned an int before, and size_t is now an unsigned int.

I was wrong about the void * fix for the warnings; I think you really want to
change '-DPTR_TYPE=unsigned char *' in the makefile to '-DPTR_TYPE=char *'.
The difference here is with the compiler; it never used to complain about
conversions from unsigned char to char.

 -Guy Middleton, University of Waterloo		gamiddleton@watmath.waterloo.edu
		(+1 519 885 1211 x3472)		gamiddleton@watmath.uwaterloo.ca