Porting klib's knetfile.c|h to windows, when I sub in the “windows unistd.h”, I get error C2036: 'void *' : unknown size

StackOverflow https://stackoverflow.com/questions/13020818

  •  13-07-2021
  •  | 
  •  

Question

First, by "windows unistd.h", I mean the example located here: "is there a replacement for unistd.h for windows?

I am attempting to massage knetfile.c so that it can be compiled for windows64. My first step was to remove the unistd.h include, because it is not available on windows.

fatal error C1083: Cannot open include file: 'unistd.h': No such file or directory

So, I figured I'd roll the dice with the drop-in replacement linked to above. However, this is clearly not working, as I now get a whole series of errors and warnings:

knetfile.c(189): error C2036: 'void *' : unknown size knetfile.c(236): warning C4267: 'function' : conversion from 'size_t' to 'int', possible loss of data

knetfile.c(264): warning C4244: '=' : conversion from 'SOCKET' to 'int', possible loss of data

knetfile.c(271): warning C4244: '=' : conversion from 'SOCKET' to 'int', possible loss of data

knetfile.c(300): warning C4244: '=' : conversion from '__int64' to 'int', possible loss of data

knetfile.c(335): error C2143: syntax error : missing ';' before 'const'

knetfile.c(336): error C2065: 'p' : undeclared identifier

knetfile.c(336): error C2100: illegal indirection

knetfile.c(336): error C2065: 'p' : undeclared identifier

knetfile.c(337): error C2065: 'p' : undeclared identifier

knetfile.c(337): error C2100: illegal indirection

knetfile.c(337): error C2065: 'p' : undeclared identifier

knetfile.c(337): error C2100: illegal indirection

knetfile.c(337): error C2065: 'p' : undeclared identifier

knetfile.c(338): error C2065: 'p' : undeclared identifier

knetfile.c(338): warning C4047: 'function' : 'const char *' differs in levels of indirection from 'int'

knetfile.c(338): warning C4024: 'strtoint64' : different types for formal and actual parameter 1

knetfile.c(378): warning C4244: '=' : conversion from '__int64' to 'int', possible loss of data

knetfile.c(410): warning C4244: '=' : conversion from 'SOCKET' to 'int', possible loss of data

knetfile.c(430): warning C4244: 'initializing' : conversion from 'int64_t' to 'off_t', possible loss of data

knetfile.c(520): error C2036: 'void *' : unknown size

knetfile.c(537): warning C4244: 'function' : conversion from 'int64_t' to 'long', possible loss of data

knetfile.c(544): warning C4244: 'return' : conversion from 'int64_t' to 'off_t', possible loss of data

knetfile.c(553): warning C4244: 'return' : conversion from 'int64_t' to 'off_t', possible loss of data

knetfile.c(565): warning C4244: 'return' : conversion from 'int64_t' to 'off_t', possible loss of data

I imagine there is a small group of macros or typedefs missing that would clear this up. Any suggestions?

Was it helpful?

Solution

The first error

knetfile.c(189): error C2036: 'void *' : unknown size

is simply correct, and the code is wrong. No amount of tinkering with header files is going to change the fact that you cannot do pointer arithmetic on void pointers.

The fifth error

knetfile.c(335): error C2143: syntax error : missing ';' before 'const'

is also correct. In C all declarations must be at the beginning of a block before any statements. Possibly that changed with C99, but Microsoft compilers don't support C99.

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top