I have the problem with the following code in D2:
CreateWindowEx returns NULL but I haven't got idea why?
module test;
import base;
static import user32;
static import kernel32;
void MsgBox(immutable char [] o_str){
user32.messageBox(null, cast(str)o_str, cast(str)msg, 0x0);
}
struct
What's wrong with this simple symbol table class?
class Symbol
{
private char[] id;
private static Symbol[char[]] symtab;
private this( string id) {
this.id = id;
}
static Symbol opCall( char[] id) {
Symbol sym = symtab[id]; // *** ArrayBoundsError here
if
You query presence of a key in an AA using 'in'
if (id in symtab) {
Symbol sym = symtab[id];
...
} else {
..
}
Or this avoids a double lookup if the symbol is present:
Symbol* pSym = id in symtab;
if (pSym !is null) {
Symbol sym = *pSym;
...
} else
Bill Baxter Wrote:
You query presence of a key in an AA using 'in'
Thank you Bill .. esp. the tip to avoid double lookup.
JJ
-BEGIN PGP SIGNED MESSAGE-
Hash: SHA1
Zarathustra wrote:
I have the problem with the following code in D2:
CreateWindowEx returns NULL but I haven't got idea why?
snip
That's because your are not properly processing all of the messages that
are involved in window creation.
See:
On Fri, Oct 16, 2009 at 4:11 PM, Manfred_Nowak svv1...@hotmail.com wrote:
Bill Baxter wrote:
Symbol* pSym = id in symtab;
shouldn't the compiler sort this out?
I'm not really sure what you mean, but I think the answer is that
there's a difference between an unset entry and one that's set
public void addToAA(char[] var_name, KT, ET)(KT key, ET element)
{
mixin(ET.stringof~`[]* elements = key in `~var_name~`;`);
if( elements == null )
{
ET[] temp;
temp.length = 1;
temp[0] = element;
mixin(var_name~`[key] = temp;`);
}
else
{
(*elements).length =
Bill Baxter:
Or this avoids a double lookup if the symbol is present:
In LDC both forms (and several other ones, if the usage of the pointer is
local, and it doesn't get passed away) get simplified to the same single lookup
code :-) (but not in DMD).
So much that you may even think of in to