Re: Toolchain with ldc and AArch64 OSX

2023-07-08 Thread Danilo Krahn via Digitalmars-d-learn

On Saturday, 24 June 2023 at 15:16:37 UTC, Cecil Ward wrote:
I have LDC running on an ARM Mac. If anyone else out there is 
an LDC or GDC user, could you knock up a quick shell program to 
compile and link a .d file to produce an executable ? found the 
linker but these tools are all new to me and a bit of help 
would save me a lot of trial and error and frustration as I try 
to find docs. GDC would be great too.


I have managed to achieve this before on a Raspberry Pi AArch64 
Linux Debian where the compiler can link and generate an 
executable just in integrated fashion in the one command. The 
OSX tools seem rather different however.


```d
import std.stdio : writeln;

void main() {
writeln("Hello, world!");
}
```

Compilation using LDC on macOS is just:

```
ldc2 --release --O3 main.d
```

Or some more options, to reduce executable size:

```
ldc2 --release --O3 --flto=full -fvisibility=hidden 
-defaultlib=phobos2-ldc-lto,druntime-ldc-lto -L=-dead_strip -L=-x 
-L=-S -L=-lz main.d

```

Executable size using first command: 1.3MB
Executable size using second command: 756KB


Re: Dynamic array of strings and appending a zero length array

2023-07-08 Thread H. S. Teoh via Digitalmars-d-learn
On Sat, Jul 08, 2023 at 05:15:26PM +, Cecil Ward via Digitalmars-d-learn 
wrote:
> I have a dynamic array of dstrings and I’m spending dstrings to it. At
> one point I need to append a zero-length string just to increase the
> length of the array by one but I can’t have a slot containing garbage.
> I thought about ++arr.length - would that work, while giving me valid
> contents to the final slot ?

Unlike C/C++, the D runtime always ensures that things are initialized
unless you explicitly tell it not to (via void-initialization). So
++arr.length will work; the new element will be initialized to
dstring.init (which is the empty string).


T

-- 
If Java had true garbage collection, most programs would delete themselves upon 
execution. -- Robert Sewell


Re: Dynamic array of strings and appending a zero length array

2023-07-08 Thread FeepingCreature via Digitalmars-d-learn

On Saturday, 8 July 2023 at 17:15:26 UTC, Cecil Ward wrote:
I have a dynamic array of dstrings and I’m spending dstrings to 
it. At one point I need to append a zero-length string just to 
increase the length of the array by one but I can’t have a slot 
containing garbage. I thought about ++arr.length - would that 
work, while giving me valid contents to the final slot ?


What I first did was
   arr ~= [];

This gave no errors but it doesn’t increase the array length, 
so it seems. Is that a bug ? Or is it supposed to do that?




You can append an element to an array. You can also append an 
array to an array. Because [] can be an array of any type, the 
compiler guesses that it's an empty `string[]` array and appends 
it to no effect.


Re: Dynamic array of strings and appending a zero length array

2023-07-08 Thread Cecil Ward via Digitalmars-d-learn

On Saturday, 8 July 2023 at 17:15:26 UTC, Cecil Ward wrote:
I have a dynamic array of dstrings and I’m spending dstrings to 
it. At one point I need to append a zero-length string just to 
increase the length of the array by one but I can’t have a slot 
containing garbage. I thought about ++arr.length - would that 
work, while giving me valid contents to the final slot ?


[...]


s/spending/appending/


Dynamic array of strings and appending a zero length array

2023-07-08 Thread Cecil Ward via Digitalmars-d-learn
I have a dynamic array of dstrings and I’m spending dstrings to 
it. At one point I need to append a zero-length string just to 
increase the length of the array by one but I can’t have a slot 
containing garbage. I thought about ++arr.length - would that 
work, while giving me valid contents to the final slot ?


What I first did was
   arr ~= [];

This gave no errors but it doesn’t increase the array length, so 
it seems. Is that a bug ? Or is it supposed to do that?


Then I tried
arr ~= ""d;
and that did work. Is there anything more efficient that I could 
do instead?


I actually have an alias for the type of the strings so that they 
can be either dstrings or wstrings with just a recompilation. How 
should I then generate a zero-length string that has th correct 
type of dstring or wstring as I am stuck with the ‘d’-suffix on 
the end of the ""d at the moment. Can I just cast ? Not a 
reinterpret cast, but a proper value conversion?