View previous topic :: View next topic |
Author |
Message |
brad Site Admin
Joined: 22 Feb 2004 Posts: 490 Location: Atlanta, GA USA
|
Posted: Mon May 31, 2004 1:12 am Post subject: struct - set to null? |
|
|
I am porting some Java code that used classes as structs (because Java lacks structs).
and later:
Code: | void releaseWidget() {
oldFont = null;
} |
The compiler (dmd 0.89, WinXP) complains that you cannot implicitly convert void* to LOGFONT.
So, what options do I have to set this struct to null or point to nothing?
(now it's char to LOGFONT)
Also, how do I do the following?
Code: | if(oldFont == null) return; |
I poked around the DM website and the Wiki, and found constructors for structs with opCall() but nothing about destructors or setting/comparing structs to null. _________________ I really like the vest! |
|
Back to top |
|
|
eye
Joined: 03 Jun 2004 Posts: 5
|
Posted: Thu Jun 03, 2004 4:10 am Post subject: |
|
|
Structs are not references. They don't "polnt" to anything. And you definately canot set them to null, or test them for being null. Your class looks like:
other fields
...
struct with all of its contents
...
other fields
that is, it is contained completely within a class.
what you want, is to either:
- make this struct a class, or
- place a pointer to the struct in the enclosing class
they both would work exactly the same in this case. |
|
Back to top |
|
|
Blandger
Joined: 21 May 2004 Posts: 50 Location: Ukraine, Kharkov
|
Posted: Thu Jun 03, 2004 7:01 am Post subject: |
|
|
eye wrote: | what you want, is to either:
- make this struct a class, or
- place a pointer to the struct in the enclosing class
they both would work exactly the same in this case. |
Brad, may be it was a bad idea converting dwt.internal.win32.* into the STRUCTS and it could be better leave it as it was in java? Or there wasn't another way because of D calling conventions, was it ? _________________ Regards, Yuriy |
|
Back to top |
|
|
eye
Joined: 03 Jun 2004 Posts: 5
|
Posted: Thu Jun 03, 2004 12:01 pm Post subject: |
|
|
If these are resemblances of WinAPI structs, they should stay structs - otherwise you cannot pass them to WinAPI functions.
In Java, this is probably different, but i heard that transition from Java to native libraries is very thick and involves a lot of conversions. As opposed to D, where it is very thin and effective.
So i think pointer to struct is right. |
|
Back to top |
|
|
brad Site Admin
Joined: 22 Feb 2004 Posts: 490 Location: Atlanta, GA USA
|
Posted: Thu Jun 03, 2004 2:48 pm Post subject: |
|
|
From the D newsgroup:
Quote: |
Vathix,
What about another struct member/property (whatever they're called).
struct LOGFONT {
...
bool isCurrent
}
I could set it to true or false and not bother with re-initializing everything.
Any thoughts as to how it would affect any .sizeof calcs in its use? I.E. any negative effects because the WinAPI is expecting a certain set of data and it would receive extra?
BA
|
and
Quote: |
Ben Hinkle wrote:
>
> I bet the Java code is explicitly setting oldFont to null to help the GC
> collect the LOGFONT as garbage. I would skip the oldFont=null in D.
And I would too, except that later, there's a test to see if LOGFONT is null.
if(LOGFONT == null)
> A related question has to do with how the port passes LOGFONT to functions:
> are you passing by value or pointer or inout?
I believe we are switching to pass them by pointer. Which is better?
BTW, LOGFONT will have extra properties if version(Unicode) is true. The old way in Java is to have a base class and the unicode and non-unicode classes inherit from it and add their wchar/char properties.
|
The top quote is the one I'm most interested. With that new property, I don't have to set the entire thing to null just to do comparisons to see if it's null or not. Actually, as Eye said, that's not possible. Anyway, I did the top quote, adding the isCurrent or isValid, and moved on. I don't know what effect that will have when I pass the struct into the WinAPI, having that extra bit of info. _________________ I really like the vest! |
|
Back to top |
|
|
|
|
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
|