[gdc-0.24_3 on freebsd8current/amd64 ]can't run socket.connect
David Friedman
dvdfrdmn at users.ess-eff.net
Sun Jun 8 12:14:57 PDT 2008
kevin wrote:
> import std.socket;
> import std.socketstream;
>
> int main()
> {
> Socket sock = new Socket(AddressFamily.INET, SocketType.STREAM,
> ProtocolType.IP);
> sock.connect(new InternetAddress("www.digitalmars.com", 80));
> SocketStream ss = new SocketStream(sock);
>
> ss.writeString("GET /d/intro.html HTTP/1.1\r\n"
> "Host: www.digitalmars.com\r\n"
> "\r\n");
>
> while(ss.readLine().length) {} //skip header
> while(!ss.eof())
> {
> char[] line;
> printf("%.*s\n", ss.readLine());
> }
>
> return 0;
> }
> ----------------------
> I try to run this. I find it compile well.but when I run it., it core dump.
Although the D spec says you can pass a string for a "%.*s" format, it
really only works on 32-bit targets. The argument for '*' is of type
'int', not 'size_t'. On a 64-bit target, passing a char[] really passes
a 'size_t' and 'char*', which is not what printf expects.
To be portable, you have to do this:
string s2 = ss.readline();
printf("%.*s\n", cast(int) s2.length, s2.ptr);
David
More information about the D.gnu
mailing list