View previous topic :: View next topic |
Author |
Message |
brad Site Admin
Joined: 22 Feb 2004 Posts: 490 Location: Atlanta, GA USA
|
Posted: Sat Jul 03, 2004 1:31 am Post subject: detecting null struct |
|
|
In Java you have the following:
Code: |
WINDOWPOS wp = lpwp [i]; // WINDOWPOS is a class in Java
if (wp != null && wp.hwnd == handle) { ... }
|
I have been doing the following:
Code: |
WINDOWPOS wp = lpwp [i]; // WINDOWPOS is a struct in D
if (cast(void*)wp != null && wp.hwnd == handle) { ... }
|
but dont' feel very good about it. Anybody have thoughts as to what I could do?
I should say that the issue is the compiler says
DMD wrote: |
incompatible types for ((wp) != (null)): 'WINDOWPOS' and 'void*'
|
because of null being a void* in D. What else can I do here?
Thanks,
BA _________________ I really like the vest! |
|
Back to top |
|
|
brad Site Admin
Joined: 22 Feb 2004 Posts: 490 Location: Atlanta, GA USA
|
Posted: Sat Jul 03, 2004 1:37 am Post subject: |
|
|
To add to this point, later in that class, I need to do the following:
lpwp is a WINDOWPOS[]
Compiler says that I can't convert void* (null) to a WINDOWPOS, which lpwp[i] is expecting.
For other structs, just to move on, I added a bool isActive to the struct and set it to 1 or 0 for these purposes. Is this what I should continue to do? Seems like quite a kludge to me... _________________ I really like the vest! |
|
Back to top |
|
|
Blandger
Joined: 21 May 2004 Posts: 50 Location: Ukraine, Kharkov
|
Posted: Sat Jul 03, 2004 4:11 am Post subject: Re: detecting null struct |
|
|
brad wrote: | In Java you have the following:
Code: |
WINDOWPOS wp = lpwp [i]; // WINDOWPOS is a class in Java
if (wp != null && wp.hwnd == handle) { ... }
|
I should say that the issue is the compiler says
Code: |
incompatible types for ((wp) != (null)): 'WINDOWPOS' and 'void*'
|
|
I'm not sure if it's right but I changed it to:
Code: |
......
WINDOWPOS[] lpwp = parent.lpwp;
if (lpwp == null) return;
for (int i=0; i<lpwp.length; i++) {
WINDOWPOS* wp = &lpwp[i];
if (wp != null && wp.hwnd == handle) {
......
|
Hope it's right. _________________ Regards, Yuriy |
|
Back to top |
|
|
kris
Joined: 27 Mar 2004 Posts: 1494 Location: South Pacific
|
Posted: Sat Jul 03, 2004 11:52 am Post subject: |
|
|
you could always leave WINDOWPOS as a class, rather than convertng it to a struct. That would avoid the re-engineering and reduce the possibility of introducing bugs. I imagine the replacement of classes with D structs is an "optimization" that might wait until things are working.
- Kris |
|
Back to top |
|
|
|