Thread overview | |||||||||
---|---|---|---|---|---|---|---|---|---|
|
December 21, 2001 null casts | ||||
---|---|---|---|---|
| ||||
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: C, C++, Pascal, BASIC... It gets especially #%#@ when 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. |
December 21, 2001 Re: null casts | ||||
---|---|---|---|---|
| ||||
Posted in reply to Pavel Minayev | 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: > C, C++, Pascal, BASIC... It gets especially #%#@ when > 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. > > |
December 22, 2001 Re: null casts | ||||
---|---|---|---|---|
| ||||
Posted in reply to Pavel Minayev | 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: > C, C++, Pascal, BASIC... It gets especially #%#@ when > 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. > > |
December 22, 2001 Re: null casts | ||||
---|---|---|---|---|
| ||||
Posted in reply to Walter | "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... |
December 22, 2001 Re: null casts | ||||
---|---|---|---|---|
| ||||
Posted in reply to Pavel Minayev | 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... |
December 22, 2001 Re: null casts | ||||
---|---|---|---|---|
| ||||
Posted in reply to Pavel Minayev | 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: > C, C++, Pascal, BASIC... It gets especially #%#@ when > 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. |
December 22, 2001 Re: null casts | ||||
---|---|---|---|---|
| ||||
Posted in reply to Sean L. Palmer | 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 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: > > C, C++, Pascal, BASIC... It gets especially #%#@ when > > 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. > > > |
Copyright © 1999-2021 by the D Language Foundation