Re: Up to date documentation on D implementation.

2012-04-07 Thread Dmitry Olshansky

On 07.04.2012 8:51, ReneSac wrote:

On Friday, 6 April 2012 at 01:33:10 UTC, Mike Parker wrote:

DMD runs just fine on 64-bit Windows.

Then why 32 bit Windows (Win32) operating system, such as Windows XP
is put as a requirement? This should be corrected:
http://dlang.org/dmd-windows.html

Anyway, in the mean time I have setup GDC using the latest binaries, and
it is working well.

The only thing I noticed is that a simple Hello World took several
seconds to compile, and ended up with 1.25MB (release, non-debug build)!


how about strip it?
+ MinGW debug info is notoriously bloated (if it was debug build).


And I thought that D was fast to compile... But then I discovered that
switching to std.c.stdio made the compilation almost instantaneous, and
the executable size a slightly more reasonable 408KB. It works, but that
isn't really an option, as D strings aren't readily compatible with C
strings...

I know that the lower limiter in binary size is higher, due to the
statically compiled runtime, but this bloat in the std lib for a
single function worries me a bit. Is DMD better in this measurement, or
is it a limitation of the current D libraries?

This may be kinda important latter, as in compression benchmarks, the
decompressor size is added in the compressed size to prevent cheating. I
don't want a multi-megabyte executable size.




--
Dmitry Olshansky


Re: parallel unzip in progress

2012-04-07 Thread Jay Norwood

On Wednesday, 4 April 2012 at 19:41:21 UTC, Jay Norwood wrote:
  The work-around was to convert all the file operations to use
std.stream equivalents, and that worked well, but I see i the 
bug reports that even that was only working correctly on 
windows.  So I'm on windows, and ok for me, but it would be too 
bad to limit use to Windows.


Seems like stdio runtime support for File operations above 2GB 
would be a basic expectation for a system language these days.



btw, I posted a fix to setTimes that enables it to update the 
timestamp on directories as well as regular files, along with the 
source code of this example.



I also did some research on why ntfs is such a dog when doing 
delete operations on hard drives, as well as spending several 
hours looking at procmon logs, and have decided that the problem 
is primarily related to multiple accesses in the master file 
table file for the larger files.  There is much discussion on the 
matter of the MFT getting fragmented on these larger drives, and  
a couple of interesting  proposed tweaks in the second link.


http://ixbtlabs.com/articles/ntfs/index3.html
http://www.gilsmethod.com/speed-up-vista-with-these-simple-ntfs-tweaks

The second link shows you how to reserve a larger area for MFT, 
and the link below looks like it might be able to clean out any 
files from the reserved MFT spaces.


http://www.mydefrag.com/index.html







Re: Win GUI Single Exe - Newbie

2012-04-07 Thread Jacob Carlborg

On 2012-04-06 17:37, Jesse Phillips wrote:

I can't recommend whether D should or shouldn't be used based on your
description. You can build stand alone GUI apps with DFL, and probably
DWT. QtD and GtkD likely need their libraries shipped around.

Documentation is pretty bad for DFL, but DWT has all the SWT docs and
translation isn't bad.


Building stand alone executables with DWT works great. DWT doesn't 
depend on any third party libraries, only on the system libraries.


--
/Jacob Carlborg


Re: D1, D2, Tango, Phobos, Std, Runtime

2012-04-07 Thread Jacob Carlborg

On 2012-04-06 17:43, H. S. Teoh wrote:


The whole Tango vs. Phobos debacle happened during D1 (which is a
snapshot of an early version of D), allegedly due to some issues in
Phobos. That issue no longer exists in D2, though. Phobos is now *the*
standard library in D2. I don't think Tango is fully ported to D2 yet,
although I heard someone was working on it, and IIRC there is a
development snapshot of it available somewhere.


Tango is fully ported to D2. It has some advantages over Phobos, like a 
faster XML parser, cryptographic related modules and some other modules 
that Phobos still doesn't have.


--
/Jacob Carlborg


Re: SUL for Posix

2012-04-07 Thread Stewart Gordon

On 05/04/2012 14:51, Jacob Carlborg wrote:
snip

http://dlang.org/phobos/std_getopt.html

But it might not do what you want.


Where is the code in std.getopt that has any relevance whatsoever to 
what smjg.libs.util.datetime or smjg.libs.util.commandline is for?


Stewart.


GC-less tutorial?

2012-04-07 Thread Tove

Hi,

are there any good tutorials for using D totally without GC, 
detailing some common pitfalls?


One thing on my wishlist would be a way to detect accidental GC 
allocations resulting from side-effects of every-day 
operations... generating linking errors would be sufficient for 
detecting this...




Re: Up to date documentation on D implementation.

2012-04-07 Thread ReneSac

On Saturday, 7 April 2012 at 06:21:16 UTC, Dmitry Olshansky wrote:

On 07.04.2012 8:51, ReneSac wrote:
The only thing I noticed is that a simple Hello World took 
several
seconds to compile, and ended up with 1.25MB (release, 
non-debug build)!


how about strip it?
+ MinGW debug info is notoriously bloated (if it was debug 
build).


I said it was a non-debug build. The debug build for the Hello 
World is 7.6MB.





Re: D1, D2, Tango, Phobos, Std, Runtime

2012-04-07 Thread Andre Tampubolon
On 04/07/2012 07:28 PM, Jacob Carlborg wrote:
 Tango is fully ported to D2. It has some advantages over Phobos, like a 
 faster XML parser, cryptographic related modules and some other modules that 
 Phobos still doesn't have.

Tango is fully ported to D2? Really? You are talking about 
https://github.com/SiegeLord/Tango-D2, right?
 



Re: SUL for Posix

2012-04-07 Thread Jacob Carlborg

On 2012-04-07 14:36, Stewart Gordon wrote:

On 05/04/2012 14:51, Jacob Carlborg wrote:
snip

http://dlang.org/phobos/std_getopt.html

But it might not do what you want.


Where is the code in std.getopt that has any relevance whatsoever to
what smjg.libs.util.datetime or smjg.libs.util.commandline is for?

Stewart.


Both std.getopt and mjg.libs.util.commandline handle command line 
arguments?


--
/Jacob Carlborg


Re: GC-less tutorial?

2012-04-07 Thread Jacob Carlborg

On 2012-04-07 17:25, Tove wrote:

Hi,

are there any good tutorials for using D totally without GC, detailing
some common pitfalls?

One thing on my wishlist would be a way to detect accidental GC
allocations resulting from side-effects of every-day operations...
generating linking errors would be sufficient for detecting this...



The GC is plugable at link time, just remove it and you'll get linker 
errors when it's used.


--
/Jacob Carlborg


Re: GC-less tutorial?

2012-04-07 Thread Artur Skawina
On 04/07/12 17:25, Tove wrote:
 Hi,
 
 are there any good tutorials for using D totally without GC, detailing some 
 common pitfalls?
 
 One thing on my wishlist would be a way to detect accidental GC allocations 
 resulting from side-effects of every-day operations... generating linking 
 errors would be sufficient for detecting this...

One problem with this is that the runtime wants to alloc some things before your
code gets to run - so you can't just remove the functions from the build. You're
left with either modifying the runtime or somehow ignoring the initial 
allocations
(which usually won't cause any problems). If using a custom RT would have been 
an
option you wouldn't be asking these questions (as you could just omit the 
symbols),
so...

If your platform supports gdb, try creating a text file trapallocs containing:

b gc_malloc
b gc_qalloc
b gc_calloc
b gc_realloc
b gc_extend

then run gdb -x ./trapallocs -ex run --args ./your_app

The debugger will stop at the first allocation and you can then use bt
to check what's going on, then c to skip to the next alloc. The first few
will come from the runtime and various module ctors, but anything after
that will be caused by your code, directly or indirectly.

You can also trap just the array ops with eg:

b _d_arraycatT
b _d_arraycatnT
b _d_arrayappendT
b _d_arrayappendcTp
b _d_newarrayT

etc 

Once the runtime becomes a shared library simpler solutions will be possible,
but, until then, it doesn't get much better than this. You need some way to 
determine which allocations are legal and which are not; doing this w/o
a custom runtime is probably not worth the effort...

And, yes, the initial runtime allocations could (and should) me made to use a
different path; some of them shouldn't happen at all. For example std.datetime
alone causes two allocs via _d_newclass, in every D app that imports 
std.stdio...


artur


License for D setup

2012-04-07 Thread vmars316
Greetings,
I am getting interested in D.
Pls, what License is for D setup.
Is it free?
Also, what operating systems can D run on?
Win7, Mac,?
Thanks...Vernon


Re: License for D setup

2012-04-07 Thread q66

On Saturday, 7 April 2012 at 17:48:14 UTC, vmars316 wrote:

Greetings,
I am getting interested in D.
Pls, what License is for D setup.
Is it free?
Also, what operating systems can D run on?
Win7, Mac,?
Thanks...Vernon


Runs on Windows (x86), Linux (x86, 86_64), OS X (x86, x86_64) and 
FreeBSD (x86, x86_64).


The compiler frontend is dual licensed under GPL/Artistic, the 
backend under a single-user non-redistribution source-available 
license.


The standard and runtime libraries are Boost licensed.


Re: SUL for Posix

2012-04-07 Thread Stewart Gordon

On 07/04/2012 17:54, Jacob Carlborg wrote:
snip

Both std.getopt and mjg.libs.util.commandline handle command line
arguments?


What's that to do with anything?

If the code I need to finish smjg.libs.util.commandline is somewhere in 
std.getopt, please tell me where exactly it is.


If it isn't, then why did you refer me to it?  That's like telling 
someone who's writing a bigint library and struggling to implement 
multiplication to just look in std.math.  After all, they both handle 
numbers.


Stewart.


Re: License for D setup

2012-04-07 Thread vmars316
q66 Wrote:
 On Saturday, 7 April 2012 at 17:48:14 UTC, vmars316 wrote:
  Greetings,
  I am getting interested in D.
 
 Runs on Windows (x86), Linux (x86, 86_64), OS X (x86, x86_64) and 
 FreeBSD (x86, x86_64).
 
 The compiler frontend is dual licensed under GPL/Artistic, the 
 backend under a single-user non-redistribution source-available 
 license.
 
 The standard and runtime libraries are Boost licensed.

Sounds good.
Is there an up-todate 
Getting started with D programming?
What to download, and where to install it. 
Also, is there a Visual GUI IDE? 
I have codeBlocks and GCC installed. 
Can D use wxWidgets?
Evidently, C++ can use wxWidgets, 
but C can not. Which is why I am here. 

Thanks for your helps...vm 







Re: License for D setup

2012-04-07 Thread simendsjo

On Sat, 07 Apr 2012 20:37:16 +0200, vmars316 vmars...@live.com wrote:


Sounds good.
Is there an up-todate
Getting started with D programming?
What to download, and where to install it.
Also, is there a Visual GUI IDE?
I have codeBlocks and GCC installed.
Can D use wxWidgets?
Evidently, C++ can use wxWidgets,
but C can not. Which is why I am here.

Thanks for your helps...vm



http://dlang.org has a lot of information.

Download: http://dlang.org/download.html
Tutorial: http://www.informit.com/articles/article.aspx?p=1381876
Editors: http://prowiki.org/wiki4d/wiki.cgi?EditorSupport
GUI libs: http://prowiki.org/wiki4d/wiki.cgi?GuiLibraries


Re: SUL for Posix

2012-04-07 Thread Jacob Carlborg

On 2012-04-07 19:57, Stewart Gordon wrote:

On 07/04/2012 17:54, Jacob Carlborg wrote:
snip

Both std.getopt and mjg.libs.util.commandline handle command line
arguments?


What's that to do with anything?

If the code I need to finish smjg.libs.util.commandline is somewhere in
std.getopt, please tell me where exactly it is.

If it isn't, then why did you refer me to it? That's like telling
someone who's writing a bigint library and struggling to implement
multiplication to just look in std.math. After all, they both handle
numbers.

Stewart.


I don't know what your module is supposed to do.

--
/Jacob Carlborg


Re: SUL for Posix

2012-04-07 Thread Stewart Gordon

On 07/04/2012 20:16, Jacob Carlborg wrote:
snip

I don't know what your module is supposed to do.


Then how about reading its documentation?
http://pr.stewartsplace.org.uk/d/sutil/doc/commandline.html

If there's something you don't understand about it, this is the issue 
that needs to be addressed, rather than wildly guessing that some Phobos 
module provides the answer.


Stewart.


Re: License for D setup

2012-04-07 Thread vmars316

On Saturday, 7 April 2012 at 19:03:25 UTC, simendsjo wrote:

On Sat, 07 Apr 2012 20:37:16 +0200, vmars316




http://dlang.org has a lot of information.

Download: http://dlang.org/download.html
Tutorial: 
http://www.informit.com/articles/article.aspx?p=1381876

Editors: http://prowiki.org/wiki4d/wiki.cgi?EditorSupport
GUI libs: http://prowiki.org/wiki4d/wiki.cgi?GuiLibraries


Thanks for the links.
Lots of good info, I am a bit overwhelmed.
I downloaded dinstaller.exe for windows
using this guideline: 
http://www.youtube.com/watch?v=kSugYSC5hrEfeature=related

C:\D
Where/how can I tell exactly what is installed?
DMG? GTK? QT?
But I can't figure out how to get it going.
The first thing I would like to do:
1) Run the hello world program.
and
2) I want to install a Visual GUI IDE (drag and drop Visual 
Controls).
Can I get some recommendations on What Visual IDEs people are 
using?

Am I using the right term  Visual GUI IDE ?
Maybe I should start a new Topic for this?
Thanks...Vernon



Re: Win GUI Single Exe - Newbie

2012-04-07 Thread vmars316

On Saturday, 7 April 2012 at 12:25:27 UTC, Jacob Carlborg wrote:

On 2012-04-06 17:37, Jesse Phillips wrote:


Building stand alone executables with DWT works great. DWT 
doesn't depend on any third party libraries, only on the system 
libraries.


I downloaded and installed dinstaller.exe using this HowTo:
 http://www.youtube.com/watch?v=kSugYSC5hrEfeature=related
What would I need to have installed to run DWT?
How about VisualD, is it any good?
Any recommends would be greatly appreciated.
Thanks...vmars


asm stackframe question

2012-04-07 Thread Stefan
As a little learning exercise for D I’m writing a fixed point 
library. Part of this is checking standard integer operations for 
overflows.


This is the code for adding 2 longs:

int64 add64ov(int64 a, int64 b) {
int64 res;
 asm {
mov EAX,a;
mov EDX,a+4  ;
add EAX,b;
adc EDX,b+4  ;
jo  overflow ;
		mov res,EAX  ; // Not optimal: cannot do a ret here because of 
stack frame previously not correctly set

mov res+4,EDX;
}
return res;
overflow:
throw new OverflowException(Overflow in 64 bit addition);
}

The detour via the res variable is costly; the standard epilogue
(I probably need a frame pointer for the exception throw to work):
  mov ESP, EBP
  pop EBP
  ret

creates an access violation.

Ideas, anyone?


Static Associative Arrays

2012-04-07 Thread Caligo
I'm not questioning the design, but I would like to know the reason:
given the fact that associative arrays are built into the language,
why don't we have static associative arrays?


Input from a newbie

2012-04-07 Thread Jonas

Hello D community! :-)

I was looking for a sane, object-oriented, 
possible-to-go-low-level programming language, so I decided to 
give D a try today.


Here's some feedback on the things I had/have trouble with. I 
hope some of this may be valuable for you.


1) First off, I really couldn't figure out were I was supposed to 
post this sort of message.  Apparently there aren't any mailing 
lists (a la Google groups) for D?


2) I couldn't find any good documentation on the build process 
and tools I'm supposed to use. Do you guys use standard 
Makefiles? Do you have your own build system? Would be really 
helpful if that was covered on the website.


3) While your error messages are a lot better than GCCs (gives 
you more context, hints about how the compiler interpreted your 
buggy program, etc) it wouldn't hurt if you made them a bit more 
graphical using colors and markers and such (LLVM like).


4) What's the difference between `... foo(MyObject obj) { ... }` 
and `foo(MyObject* obj)`? What are use cases for explicit 
pointers when passing objects? That's not covered in the 
documentation AFAIT.


5) What's wrong with this program? Is it that `printf` doesn't 
understand D strings? If so, how do I use D strings in string 
formatting?


import std.stdio;

string foo() { return foobar; }

int main() {
  printf(%s\n, foo());
  return 0;
}


Jonas


Re: Input from a newbie

2012-04-07 Thread Stefan

On Saturday, 7 April 2012 at 22:21:36 UTC, Jonas wrote:

Hello D community! :-)

I was looking for a sane, object-oriented, 
possible-to-go-low-level programming language, so I decided to 
give D a try today.


good choice, welcome! ;-)

4) What's the difference between `... foo(MyObject obj) { ... 
}` and `foo(MyObject* obj)`? What are use cases for explicit 
pointers when passing objects? That's not covered in the 
documentation AFAIT.


You normally don't need pointers. Objects are always passed by
reference. So MyObject* obj would be redundant.

5) What's wrong with this program? Is it that `printf` doesn't 
understand D strings? If so, how do I use D strings in string 
formatting?


import std.stdio;

string foo() { return foobar; }

int main() {
  printf(%s\n, foo());
  return 0;
}


printf is a C function which expects 0-terminated strings. D's
strings are variable-length arrays and not zero-terminated.

Don't use printf. Try using writef instead. Same arguments.

Stefan


Re: asm stackframe question

2012-04-07 Thread bearophile

Stefan:


Ideas, anyone?


Use the naked attribute and do it all by yourself? Keep also in 
mind that D functions that contain ASM don't get inlined in DMD 
(and probably elsewhere too).


Bye,
bearophile


Re: Input from a newbie

2012-04-07 Thread bearophile

Jonas:


Hello D community! :-)


Welcome here.


I was looking for a sane, object-oriented, 
possible-to-go-low-level programming language, so I decided to 
give D a try today.


D supports OOP well enough, but template-based programming seems 
equally fit or even more. Also keep in mind that the D GC is not 
so efficient, so avoid creating too many small objects, as you do 
in Java.



1) First off, I really couldn't figure out were I was supposed 
to post this sort of message.


This is the right place.


2) I couldn't find any good documentation on the build process 
and tools I'm supposed to use. Do you guys use standard 
Makefiles? Do you have your own build system? Would be really 
helpful if that was covered on the website.


One tool fit for not huge programs is rdmd. I use bud still, 
but it's getting obsolete.



3) While your error messages are a lot better than GCCs (gives 
you more context, hints about how the compiler interpreted your 
buggy program, etc) it wouldn't hurt if you made them a bit 
more graphical using colors and markers and such (LLVM like).


I don't think Walter will love this idea.


4) What's the difference between `... foo(MyObject obj) { ... 
}` and `foo(MyObject* obj)`?


If obj is a class instance, then the first syntax is the one you 
will find in D programs.



What are use cases for explicit pointers when passing objects? 
That's not covered in the documentation AFAIT.


It's not documented because you don't use explicit pointers to 
pass objects around. Pointers are used to pass structs around 
when you don't want to copy them.



5) What's wrong with this program? Is it that `printf` doesn't 
understand D strings? If so, how do I use D strings in string 
formatting?


Use write, writef, writeln, writefln for D strings and for 
several other D data structures.


Take a look here for many small examples programs in D to do many 
different kind of things (not all of them are up to date or fully 
correct, but most of them are good, and the wrong ones are being 
fixed one after the other):

http://rosettacode.org/wiki/Category:D

Bye,
bearophile


Re: Input from a newbie

2012-04-07 Thread ReneSac

On Saturday, 7 April 2012 at 22:21:36 UTC, Jonas wrote:


5) What's wrong with this program? Is it that `printf` doesn't 
understand D strings? If so, how do I use D strings in string 
formatting?


import std.stdio;

string foo() { return foobar; }

int main() {
  printf(%s\n, foo());
  return 0;
}



You can use toStringz() from std.string to convert D strings to 
null terminated strings when you need to interface with C 
functions. But in this case, writeln() would be the simplest 
solution. It would be only:


writeln(foo());

Instead of:

printf(%s\n, toStringz(foo()));

I'm a newbie in D too, so correct me if there is anything wrong.


Re: asm stackframe question

2012-04-07 Thread Timon Gehr

On 04/08/2012 12:13 AM, Stefan wrote:

As a little learning exercise for D I’m writing a fixed point library.
Part of this is checking standard integer operations for overflows.

This is the code for adding 2 longs:

int64 add64ov(int64 a, int64 b) {
int64 res;
asm {
mov EAX,a ;
mov EDX,a+4 ;
add EAX,b ;
adc EDX,b+4 ;
jo overflow ;
mov res,EAX ; // Not optimal: cannot do a ret here because of stack
frame previously not correctly set
mov res+4,EDX;
}
return res;
overflow:
throw new OverflowException(Overflow in 64 bit addition);
}

The detour via the res variable is costly; the standard epilogue
(I probably need a frame pointer for the exception throw to work):
mov ESP, EBP
pop EBP
ret

creates an access violation.

Ideas, anyone?


The D calling convention leaves stack cleanup up to the callee. Either 
mark your function as extern(C) or use


leave
ret 16

The second option might not be portable across all currently available 
compilers though.


Re: Input from a newbie

2012-04-07 Thread Jonathan M Davis
On Sunday, April 08, 2012 00:21:35 Jonas wrote:
 1) First off, I really couldn't figure out were I was supposed to
 post this sort of message.  Apparently there aren't any mailing
 lists (a la Google groups) for D?

These are both newsgroups and mailing lists, and there's forum software on top 
of it as well.

Newsgroups: http://www.digitalmars.com/NewsGroup.html
Mailing Lists: http://lists.puremagic.com/cgi-bin/mailman/listinfo
Forum: http://forum.dlang.org/

You can pick which interface you want to use. They're all the same thing. It's 
just a question of how you access it. But no, it's not quite like google 
groups.

- Jonathan M Davis


Re: Static Associative Arrays

2012-04-07 Thread Jonathan M Davis
On Saturday, April 07, 2012 18:45:40 Caligo wrote:
 I'm not questioning the design, but I would like to know the reason:
 given the fact that associative arrays are built into the language,
 why don't we have static associative arrays?

What do you mean my static associative arrays? Are you asking why you can't 
initialize a static variable which is an AA at compile time? e.g.

static int[string] aa = [hello ; 7, world, 13]; //error

That's because that would involve allocating memory at compile time which 
would then somehow have to be around at runtime. And that doesn't work right 
now. Classes have the same problem. You have to initialize them at runtime. I 
believe that dynamic arrays are the only ones that work with that right now, 
and that's because it's a difficult problem. Obviously, none of the memory 
allocated at compile time can persist to runtime, so there is no simple 
solution. At some point, it will probably be possible, but not right now. You 
_should_ be able to use them in CTFE, but they can't be assigned to anything 
that will persist until runtime.

The solution is to use static constructors to initialize AAs and class 
references at runtime. 

Now, if you're talking about something else, I have no idea what you mean by 
static AAs.

- Jonathan M Davis


string concatenation

2012-04-07 Thread dnewbie
I have a wchar[] and I want to convert it to UTF8
then append a string. This is my code.

import std.c.windows.windows;
import std.string;
import std.utf;

int main()
{
   wchar[100] v;
   v[0] = 'H';
   v[1] = 'e';
   v[2] = 'l';
   v[3] = 'l';
   v[4] = 'o';
   v[5] = 0;
   string s = toUTF8(v) ~ , world!;
   MessageBoxA(null, s.toStringz, myapp, MB_OK);
   return 0;
}

I want Hello, world!, but the result is Hello only. Please help me.


Re: string concatenation

2012-04-07 Thread Jonathan M Davis
On Sunday, April 08, 2012 07:08:09 dnewbie wrote:
 I have a wchar[] and I want to convert it to UTF8
 then append a string. This is my code.
 
 import std.c.windows.windows;
 import std.string;
 import std.utf;
 
 int main()
 {
wchar[100] v;
v[0] = 'H';
v[1] = 'e';
v[2] = 'l';
v[3] = 'l';
v[4] = 'o';
v[5] = 0;
string s = toUTF8(v) ~ , world!;
MessageBoxA(null, s.toStringz, myapp, MB_OK);
return 0;
 }
 
 I want Hello, world!, but the result is Hello only. Please help me.

D strings are not null-terminated, so v[5] = 0 doesn't do anything to 
terminate that string. The whole point of toStringz is to put a null character 
on the end of a string (and allocate a new string if need be) and return a 
pointer to it. C code will then use the null character to indicate the end of 
the string, but D won't.

What you've done with

string s = toUTF8(v) ~ , world!;

is create a string that is

['H', 'e', 'l', 'l', 'o', '\0', '\0', '\0', ...] (all of the characters up to 
the v[99] are '\0')

and append

[',', ' ', 'w', 'o', 'r', 'l', 'd', '!']

to it. The result is a string whith is 108 characters long with a ton of null 
characters in the middle of it. When you call toStringz on it, it may or may 
not allocate a new string, but in the end, you have a string which is 109 
characters long with the last character being '\0' (still with all of the null 
characters in the middle) which you get an immutable char* pointing to.

So, when the C code operates on it, it naturally stops processing when it hits 
the first null character, since that's how C determines the end of a string. 
You can embed null characters in a string and expect C to operate on the whole 
thing. And since D strings aren't null-terminated, you can't expect that 
setting any of it their elements to null will do anything to terminate the 
string in D or stop D functions from operating on the whole string. You have 
to slice the static wchar array with the exact elements that you want if you 
intend to terminate it before its end.

- Jonathan M Davis


Re: Static Associative Arrays

2012-04-07 Thread H. S. Teoh
On Sat, Apr 07, 2012 at 09:01:40PM -0700, Jonathan M Davis wrote:
 On Saturday, April 07, 2012 18:45:40 Caligo wrote:
  I'm not questioning the design, but I would like to know the reason:
  given the fact that associative arrays are built into the language,
  why don't we have static associative arrays?
 
 What do you mean my static associative arrays? Are you asking why you
 can't initialize a static variable which is an AA at compile time?
 e.g.
 
 static int[string] aa = [hello ; 7, world, 13]; //error
 
 That's because that would involve allocating memory at compile time
 which would then somehow have to be around at runtime. And that
 doesn't work right now. Classes have the same problem. You have to
 initialize them at runtime. I believe that dynamic arrays are the only
 ones that work with that right now, and that's because it's a
 difficult problem. Obviously, none of the memory allocated at compile
 time can persist to runtime, so there is no simple solution. At some
 point, it will probably be possible, but not right now. You _should_
 be able to use them in CTFE, but they can't be assigned to anything
 that will persist until runtime.
[...]

I've thought of a way to use CTFE to generate static AA's, but I appear
to be running into a CTFE bug or quirk that causes it not to work.
Basically, the idea is to use CTFE to generate a series of static struct
declarations (each struct being an AA slot) with precomputed references
between them. Obviously, the resulting AA must be immutable, but in
principle this should allow implementation of static AA's.

But I'm running into a weird issue where using a string mixin with a
string constant containing the struct definitions work correctly, but if
the string is generated piecewise by CTFE code then all references turn
into null. I'll have to massage the code a bit into a minimal test case
and open an issue on the bugtracker.


T

-- 
Windows 95 was a joke, and Windows 98 was the punchline.