FAQFAQ   SearchSearch   MemberlistMemberlist   UsergroupsUsergroups   RegisterRegister 
 ProfileProfile   Log in to check your private messagesLog in to check your private messages   Log inLog in 

detecting null struct

 
This forum is locked: you cannot post, reply to, or edit topics.   This topic is locked: you cannot edit posts or make replies.     Forum Index -> DWT
View previous topic :: View next topic  
Author Message
brad
Site Admin


Joined: 22 Feb 2004
Posts: 490
Location: Atlanta, GA USA

PostPosted: Sat Jul 03, 2004 1:31 am    Post subject: detecting null struct Reply with quote

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
View user's profile Send private message
brad
Site Admin


Joined: 22 Feb 2004
Posts: 490
Location: Atlanta, GA USA

PostPosted: Sat Jul 03, 2004 1:37 am    Post subject: Reply with quote

To add to this point, later in that class, I need to do the following:

Code:
lpwp [i] = null;


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
View user's profile Send private message
Blandger



Joined: 21 May 2004
Posts: 50
Location: Ukraine, Kharkov

PostPosted: Sat Jul 03, 2004 4:11 am    Post subject: Re: detecting null struct Reply with quote

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
View user's profile Send private message
kris



Joined: 27 Mar 2004
Posts: 1494
Location: South Pacific

PostPosted: Sat Jul 03, 2004 11:52 am    Post subject: Reply with quote

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
View user's profile Send private message
Display posts from previous:   
This forum is locked: you cannot post, reply to, or edit topics.   This topic is locked: you cannot edit posts or make replies.     Forum Index -> DWT All times are GMT - 6 Hours
Page 1 of 1

 
Jump to:  
You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum
You cannot vote in polls in this forum


Powered by phpBB © 2001, 2005 phpBB Group