Why can't I compile this DMD snippet?

36 Views Asked by At

What's wrong with this snippet where sample is of type string?

import core.stdc.stdlib: system;
   
...

compilationResult = system("rdmd -w -wi " ~ sample);

It worked with earlier versions but henever I compile it under DMD64 D Compiler v2.100.0-dirty it fails and output the following error message.

source_code.d(95): Error: function `core.stdc.stdlib.system(scope const(char*) string)` is not callable using argument types `(string)`

How should I cast the system() function's argument correctly?

1

There are 1 best solutions below

0
menjaraz On

I've managed to update some Nick Sabalausky's very old DLang code but interesting (written then under DMD 2.053 I guess), get them working under current DMD 2.100 and incidentely found the solution:

  1. Add std.string : toStringz; to the import clauses
  2. Wrap any parameter passed to system() with toStringz so as to satisfy it's new signature
  3. Update the former module owning system() with core.stdc.stdlib further to cumulative changes of the compiler