I have the error:
error C2039: 'read' : is not a member of '`global namespace'' and error C2661: 'Calc::SymString::read' : no overloaded function takes 3 arguments from the line: if (::read(fd_sock, &size, 4) != 4)
This error and similar ones appear quite a lot in my code. Does anyone know what the problem could be? I am using Windows Visual Studio 2010 and I am migrating code from Unix. Thanks in advance!
read() is a UNIX function defined (in LINUX) in unistd.h - all the documentation I have read indicates it is not a standard C function. That may be why it is compiling in UNIX but not in Windows.
In UNIX read()
takes a file descriptor, but the equivalent construct in Windows is a "handle".
Do you really need low level file descriptor I/O in your program? Can you use fread
, which is a standard C function?
This Microsoft support article describes the types of file handles available in Windows:
There are multiple types of file handles that can be opened using
the Win32 API and the C Run-time:
Returned Type File Creation API API Set
---------------------------------------------
HANDLE CreateFile() Win32
HFILE OpenFile()/_lcreat() Win32
int _creat()/_open() C Run-time
FILE * fopen() C Run-time
Microsoft declares the Unix-style I/O functions in io.h
.
Try including that header - you may get a bunch of warnings about using deprecated names (MS would prefer you use the name _read()
). If so, you may want to define the macro _POSIX_
which should quiet those warnings.
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.