[comp.lang.c] Unresolved warning - QuickC V1.1

haggas@kean.ucs.mun.ca (10/22/90)

What is the cause of the warning in the indicated line?
/* sysread.c */
/* reads and displays file - uses system I/O */
#include<fnctl.h>	/* needed for oflags in open() */
#include<stdlib.h>	/* exit() */
#include<conio.h>	/* putch() */
#include<io.h>		/* read() */
#define		BUFFSIZE	512
char buff[BUFFSIZE];	/* buffer */
void main(int, char *[]);	/* prototype for main() */

void main(argc,argv)
int argc;
char *argv[];
{
   int inhandle, bytes, j;
   if( argc != 2 )		/* check arguments */
      { printf("Format: C>sysread file.xxx"); exit(1); }
/* open file */
/* The following line has the C4051 warning - Data Conversion. Why? */
   if( (inhandle = open(argv[1], O_RDONLY | O_BINARY)) < 0 )
      { printf("Can't open file %s.", argv[1]); exit(1); }
/* read one buffer */
   while( (bytes = read(inhandle, buff, BUFFSIZE)) > 0 )
      for(j=0; j<bytes; j++)	/* print buffer */
         putch(buff[j]);
   close(inhandle);		/* close file */
}
I have tried typecasting: the value of open(), argv[1], and the constants:
O_RDONLY and O_BINARY to no avail. I have tried including the header files:
sys\types.h and sys\stat.h, to no avail. I must also point out that this
warning occurs only with QuickC and not with the Micorsoft Optimizing 
Compiler. And last but not least, this program does work!

haggas@kean.ucs.mun.ca (10/25/90)

In article <147848@kean.ucs.mun.ca>, haggas@kean.ucs.mun.ca writes:
> What is the cause of the warning in the indicated line?
> /* sysread.c */
> /* reads and displays file - uses system I/O */
> #include<fnctl.h>	/* needed for oflags in open() */
> #include<stdlib.h>	/* exit() */
> #include<conio.h>	/* putch() */
> #include<io.h>		/* read() */
> #define		BUFFSIZE	512
> char buff[BUFFSIZE];	/* buffer */
> void main(int, char *[]);	/* prototype for main() */
> 
> void main(argc,argv)
> int argc;
> char *argv[];
> {
>    int inhandle, bytes, j;
>    if( argc != 2 )		/* check arguments */
>       { printf("Format: C>sysread file.xxx"); exit(1); }
> /* open file */
> /* The following line has the C4051 warning - Data Conversion. Why? */
>    if( (inhandle = open(argv[1], O_RDONLY | O_BINARY)) < 0 )
>       { printf("Can't open file %s.", argv[1]); exit(1); }
> /* read one buffer */
>    while( (bytes = read(inhandle, buff, BUFFSIZE)) > 0 )
>       for(j=0; j<bytes; j++)	/* print buffer */
>          putch(buff[j]);
>    close(inhandle);		/* close file */
> }
> I have tried typecasting: the value of open(), argv[1], and the constants:
> O_RDONLY and O_BINARY to no avail. I have tried including the header files:
> sys\types.h and sys\stat.h, to no avail. I must also point out that this
> warning occurs only with QuickC and not with the Micorsoft Optimizing 
> Compiler. And last but not least, this program does work!

I wish to thank the net for the response I received to this question.
Here is the answer:
if( (inhandle = open(argv[1], (int)(O_RDONLY | O_BINARY))) < 0 )
   { printf("Can't open file %s.", argv[1]); exit(1); }

In the QuickC V1.01 environment, the OR'd oflags had to be typecast as as
integer to suppress the class 2 warning, on compilation.