D - null casts
- Pavel Minayev (9/9) Dec 21 2001 I've raised this topic once, still...
- Walter (3/12) Dec 21 2001 You're probably right. -Walter
- Walter (9/18) Dec 21 2001 I don't understand. The following works:
- Pavel Minayev (12/19) Dec 22 2001 Try this:
- Walter (3/13) Dec 22 2001 Ok, I see the problem. It'll get fixed. -Walter
- Sean L. Palmer (7/16) Dec 22 2001 I agree about NULL being compatible with other pointer types, but disagr...
- Walter (5/22) Dec 22 2001 I fixed D so that null is compatible with other pointer and reference ty...
I've raised this topic once, still... I don't understand why null should be casted to whatever type you want other than void*? It's so annoying! Just look around, no other language has such a restriction: calling WinAPI functions, since many arguments are usually nulls. Just let null be compatible with any pointer type. Or, even better, make void* compatible with all pointers, like it was in C.
Dec 21 2001
You're probably right. -Walter "Pavel Minayev" <evilone omen.ru> wrote in message news:a0044r$1m2p$1 digitaldaemon.com...I've raised this topic once, still... I don't understand why null should be casted to whatever type you want other than void*? It's so annoying! Just look around, no other language has such a restriction: calling WinAPI functions, since many arguments are usually nulls. Just let null be compatible with any pointer type. Or, even better, make void* compatible with all pointers, like it was in C.
Dec 21 2001
I don't understand. The following works: object test() { return null; } works, as well as object*, int*, etc. Can you please post an example where it doesn't? Thanks! "Pavel Minayev" <evilone omen.ru> wrote in message news:a0044r$1m2p$1 digitaldaemon.com...I've raised this topic once, still... I don't understand why null should be casted to whatever type you want other than void*? It's so annoying! Just look around, no other language has such a restriction: calling WinAPI functions, since many arguments are usually nulls. Just let null be compatible with any pointer type. Or, even better, make void* compatible with all pointers, like it was in C.
Dec 21 2001
"Walter" <walter digitalmars.com> wrote in message news:a00pf9$24ri$1 digitaldaemon.com...I don't understand. The following works: object test() { return null; } works, as well as object*, int*, etc. Can you please post an example where it doesn't? Thanks!Try this: import windows; int main(char[][] args) { HANDLE x = null; } HANDLE is a typedef for void*, and thus a pointer type, so it should be compatible with null, right? Still it isn't. As the result, when working with API heavily, you have to cast null to HANDLE all the time...
Dec 22 2001
Ok, I see the problem. It'll get fixed. -Walter "Pavel Minayev" <evilone omen.ru> wrote in message news:a01g85$2ma7$1 digitaldaemon.com...Try this: import windows; int main(char[][] args) { HANDLE x = null; } HANDLE is a typedef for void*, and thus a pointer type, so it should be compatible with null, right? Still it isn't. As the result, when working with API heavily, you have to cast null to HANDLE all the time...
Dec 22 2001
I agree about NULL being compatible with other pointer types, but disagree about void* being implicitly convertable to other pointer types. That leaves a gaping hole in the typechecking safety net that will end up causing bugs. That is why C++ "fixed" that problem. Sean "Pavel Minayev" <evilone omen.ru> wrote in message news:a0044r$1m2p$1 digitaldaemon.com...I've raised this topic once, still... I don't understand why null should be casted to whatever type you want other than void*? It's so annoying! Just look around, no other language has such a restriction: calling WinAPI functions, since many arguments are usually nulls. Just let null be compatible with any pointer type. Or, even better, make void* compatible with all pointers, like it was in C.
Dec 22 2001
I fixed D so that null is compatible with other pointer and reference types, but other void*'s will require an explicit cast. -Walter "Sean L. Palmer" <spalmer iname.com> wrote in message news:a02rnb$iij$1 digitaldaemon.com...I agree about NULL being compatible with other pointer types, but disagree about void* being implicitly convertable to other pointer types. That leaves a gaping hole in the typechecking safety net that will end upcausingbugs. That is why C++ "fixed" that problem. Sean "Pavel Minayev" <evilone omen.ru> wrote in message news:a0044r$1m2p$1 digitaldaemon.com...I've raised this topic once, still... I don't understand why null should be casted to whatever type you want other than void*? It's so annoying! Just look around, no other language has such a restriction: calling WinAPI functions, since many arguments are usually nulls. Just let null be compatible with any pointer type. Or, even better, make void* compatible with all pointers, like it was in C.
Dec 22 2001