digitalmars.D.learn - Why is a cast needed here?
- Dave (14/14) Nov 25 2006 import std.socket;
- Daniel Giddings (6/24) Nov 26 2006 Looks like its a bug in 0.175, I've just needed to add the same casts to...
- Chris Miller (11/43) Nov 26 2006 o
- Dave (28/69) Nov 26 2006 Here's a minimal test-case. I'll formalize it w/ a bug report.
import std.socket; void main() { //Socket s = new Socket(AddressFamily.INET,SocketType.STREAM,ProtocolType.TCP); Socket s = new Socket(cast(AddressFamily)AddressFamily.INET,SocketType.STREAM,ProtocolType.TCP); } Why is the 'cast(AddressFamily)' needed? W/o the cast: t.d(5): constructor std.socket.Socket.this () does not match parameter types (int,SocketType,ProtocolType) t.d(5): Error: cannot implicitly convert expression (2) of type int to AddressFamily t.d(5): Error: cannot implicitly convert expression (6) of type ProtocolType to char[] t.d(5): Error: cannot cast int to char[] Thanks!
Nov 25 2006
Looks like its a bug in 0.175, I've just needed to add the same casts to my code. It's a compiler issue rather than a lib issue, as the SocketType and ProtocolType are declared as enums in the same way, but don't need the cast. :-) Dan "Dave" <Dave_member pathlink.com> wrote in message news:eka11i$15v4$1 digitaldaemon.com...import std.socket; void main() { //Socket s = new Socket(AddressFamily.INET,SocketType.STREAM,ProtocolType.TCP); Socket s = new Socket(cast(AddressFamily)AddressFamily.INET,SocketType.STREAM,ProtocolType.TCP); } Why is the 'cast(AddressFamily)' needed? W/o the cast: t.d(5): constructor std.socket.Socket.this () does not match parameter types (int,SocketType,ProtocolType) t.d(5): Error: cannot implicitly convert expression (2) of type int to AddressFamily t.d(5): Error: cannot implicitly convert expression (6) of type ProtocolType to char[] t.d(5): Error: cannot cast int to char[] Thanks!
Nov 26 2006
"Dave" <Dave_member pathlink.com> wrote in message news:eka11i$15v4$1 digitaldaemon.com...olType.TCP);import std.socket; void main() { //Socket s =3D new Socket(AddressFamily.INET,SocketType.STREAM,ProtocolType.TCP); Socket s =3D new Socket(cast(AddressFamily)AddressFamily.INET,SocketType.STREAM,Protoc=r} Why is the 'cast(AddressFamily)' needed? W/o the cast: t.d(5): constructor std.socket.Socket.this () does not match paramete=otypes (int,SocketType,ProtocolType) t.d(5): Error: cannot implicitly convert expression (2) of type int t=On Sun, 26 Nov 2006 05:25:33 -0500, Daniel Giddings = <daniel.giddings gmail.com> wrote:AddressFamily t.d(5): Error: cannot implicitly convert expression (6) of type ProtocolType to char[] t.d(5): Error: cannot cast int to char[] Thanks!Looks like its a bug in 0.175, I've just needed to add the same casts =to =my code. It's a compiler issue rather than a lib issue, as the SocketType==and ProtocolType are declared as enums in the same way, but don't need the==cast. :-) DanI run into this issue with other code as well. I think it has to do with= = different enums used by overloaded functions.
Nov 26 2006
Chris Miller wrote:Here's a minimal test-case. I'll formalize it w/ a bug report. void main() { // foo f = new foo(cast(AddressFamily)AddressFamily.INET); foo f = new foo(AddressFamily.INET); } class foo { this(AddressFamily f) { } } // from std.c.linux.socket enum: int { AF_INET = 2 } // from std.c.linux.socket struct sockaddr_in { short sin_family = AF_INET; } // from std.socket enum AddressFamily: int { INET = AF_INET }"Dave" <Dave_member pathlink.com> wrote in message news:eka11i$15v4$1 digitaldaemon.com...On Sun, 26 Nov 2006 05:25:33 -0500, Daniel Giddings <daniel.giddings gmail.com> wrote:import std.socket; void main() { //Socket s = new Socket(AddressFamily.INET,SocketType.STREAM,ProtocolType.TCP); Socket s = new Socket(cast(AddressFamily)AddressFamily.INET,SocketType.STREA ,ProtocolType.TCP); } Why is the 'cast(AddressFamily)' needed? W/o the cast: t.d(5): constructor std.socket.Socket.this () does not match parameter types (int,SocketType,ProtocolType) t.d(5): Error: cannot implicitly convert expression (2) of type int to AddressFamily t.d(5): Error: cannot implicitly convert expression (6) of type ProtocolType to char[] t.d(5): Error: cannot cast int to char[] Thanks!Looks like its a bug in 0.175, I've just needed to add the same casts to my code. It's a compiler issue rather than a lib issue, as the SocketType and ProtocolType are declared as enums in the same way, but don't need the cast. :-) DanI run into this issue with other code as well. I think it has to do with different enums used by overloaded functions.
Nov 26 2006