port of redo-c to BetterC
aquaratixc
disconnectix at gmail.com
Thu Jun 10 10:23:00 UTC 2021
On Thursday, 10 June 2021 at 10:04:38 UTC, Dennis wrote:
> On Thursday, 10 June 2021 at 09:53:36 UTC, aquaratixc wrote:
>> there is a function ```redo_ifchange (int targetc, char **
>> targetv)``` inside which the ```char [targetc] skip;``` array
>> is defined;
>
> That's a Variable-length array which D doesn't support.
> If `targetc` has an upper bound, you can use a static array
> instead:
> ```D
> import core.stdc.stdlib;
>
> void redo_ifchange (int targetc, char ** targetv) {
> char[4096] buf = void;
> assert(targetc <= buf.length);
> char* skip = buf.ptr;
> // code
> }
> ```
>
> For larger sizes, you can use heap-allocation:
> ```D
> import core.stdc.stdlib;
>
> void redo_ifchange (int targetc, char ** targetv) {
> char* skip = cast(char*) malloc(targetc * char.sizeof);
> scope(exit) free(skip);
> // code
> }
> ```
>
> And if you really want variable-size stack allocation, you can
> use `alloca`:
> ```D
> import core.stdc.stdlib;
>
> void redo_ifchange (int targetc, char ** targetv) {
> char* skip = cast(char*) alloca(targetc * char.sizeof);
> // code
> }
> ```
> Though I don't recommend it.
Thanks. Its really helpful. However, as I said, there are still
questions: in particular, there is one mistake that I could not
resolve. When I try to copy, I get an error like this: ```
redo.o:redo.d:function _D4redo13redo_ifchangeFiPPaZv: error:
undefined reference to
'_D4core3sys5posixQk4wait9WIFEXITEDFNaNbNiNfiZb'
redo.o:redo.d:function _D4redo13redo_ifchangeFiPPaZv: error:
undefined reference to
'_D4core3sys5posixQk4wait11WEXITSTATUSFNaNbNiNfiZi'
collect2: ``` although i imported ```core.sys.posix.sys.wait```
More information about the Digitalmars-d
mailing list