Jump to page: 1 2 3
Thread overview
How to convert C to D using compiler?
Dec 07, 2021
ManKey
Dec 07, 2021
12345swordy
Dec 07, 2021
ManKey
Dec 07, 2021
bachmeier
Dec 08, 2021
max haughton
Dec 07, 2021
ManKey
Dec 08, 2021
Guillaume Piolat
Dec 08, 2021
bauss
Dec 08, 2021
Guillaume Piolat
Dec 08, 2021
bauss
Dec 08, 2021
Stanislav Blinov
Dec 08, 2021
Dennis
Dec 08, 2021
Stanislav Blinov
Dec 08, 2021
Dennis
Dec 09, 2021
zjh
Dec 08, 2021
Max Samukha
Dec 08, 2021
Guillaume Piolat
Dec 10, 2021
Max Samukha
Dec 10, 2021
Guillaume Piolat
Dec 10, 2021
H. S. Teoh
Dec 09, 2021
Hasan Kashi
Dec 09, 2021
ManKey
December 07, 2021

I tried this

ldc2 test.i -mixin="test.d"

but the test.d file is empty :(

December 07, 2021

On Tuesday, 7 December 2021 at 16:43:21 UTC, ManKey wrote:

>

I tried this

ldc2 test.i -mixin="test.d"

but the test.d file is empty :(

https://dlang.org/spec/importc.html

December 07, 2021

On Tuesday, 7 December 2021 at 16:49:58 UTC, 12345swordy wrote:

>

On Tuesday, 7 December 2021 at 16:43:21 UTC, ManKey wrote:

>

I tried this

ldc2 test.i -mixin="test.d"

but the test.d file is empty :(

https://dlang.org/spec/importc.html

I just want to convert from C file to D file, don't import it

December 07, 2021

On Tuesday, 7 December 2021 at 16:43:21 UTC, ManKey wrote:

>

I tried this

ldc2 test.i -mixin="test.d"

but the test.d file is empty :(

I write small script for this


import std;

string replaceExt(string path, string from, string to){
	return path.dirName ~ "/" ~ path.baseName(from) ~ to;
}

int main(string[] args){
	assert(args.length == 2);

	string src_path = args[1];
	string srci_path = src_path.replaceExt(".c", ".i");
	string renamed_path = src_path.replaceExt(".c", ".d");

	void preprocess(string orig, string ifile){
		auto result = execute(["clang", "-E", orig]);
		assert(result.status == 0, result.output);
		std.file.write(ifile, result.output);
	}

	void convert(string src, string outf){
		auto result = execute(["ldc2", src, "-vcg-ast", "-o-"]);
		assert(result.status == 0, result.output);
		rename(src ~ ".cg", outf);
	}


	preprocess(src_path, srci_path);
	convert(srci_path, renamed_path);
	std.file.remove(srci_path);

	return 0;
}
December 07, 2021

On Tuesday, 7 December 2021 at 16:52:47 UTC, ManKey wrote:

>

On Tuesday, 7 December 2021 at 16:49:58 UTC, 12345swordy wrote:

>

On Tuesday, 7 December 2021 at 16:43:21 UTC, ManKey wrote:

>

I tried this

ldc2 test.i -mixin="test.d"

but the test.d file is empty :(

https://dlang.org/spec/importc.html

I just want to convert from C file to D file, don't import it

There's no way to convert arbitrary C files to D, but:

  • You can compile C files directly if they are C11-compatible. You include them on the command line like .d files and import them the same as D modules. You have to run the C files through the preprocessor manually. There's not much support for GCC extensions.
  • You can convert header files using dstep.
  • You can include C header files directly in D modules using dpp.
December 08, 2021

On Tuesday, 7 December 2021 at 20:37:12 UTC, bachmeier wrote:

>

On Tuesday, 7 December 2021 at 16:52:47 UTC, ManKey wrote:

>

On Tuesday, 7 December 2021 at 16:49:58 UTC, 12345swordy wrote:

>

[...]

I just want to convert from C file to D file, don't import it

There's no way to convert arbitrary C files to D, but:

  • You can compile C files directly if they are C11-compatible. You include them on the command line like .d files and import them the same as D modules. You have to run the C files through the preprocessor manually. There's not much support for GCC extensions.
  • You can convert header files using dstep.
  • You can include C header files directly in D modules using dpp.

No way yet, expect a forum post / PR soon

December 08, 2021

On Tuesday, 7 December 2021 at 16:43:21 UTC, ManKey wrote:

>

I tried this

ldc2 test.i -mixin="test.d"

but the test.d file is empty :(

  • you can do it by hand
  • or instead you can wait a few years that ImportC becomes workable :)
December 08, 2021

On Wednesday, 8 December 2021 at 09:23:41 UTC, Guillaume Piolat wrote:

>

On Tuesday, 7 December 2021 at 16:43:21 UTC, ManKey wrote:

>

I tried this

ldc2 test.i -mixin="test.d"

but the test.d file is empty :(

  • you can do it by hand
  • or instead you can wait a few years that ImportC becomes workable :)

It'll probably be dropped for the next big feature before being finished, just like everything else in D. Nothing is ever completed or workable. Only ever a subset works.

Not to be pessimistic but there's literally no ground-breaking feature in D that has been finished yet.

Everything is only finished half-way through and doesn't work properly - referring to nogc, safe, shared, betterC, the many phobos modules under experimental.

D has this mentality that it's better to start something new and exciting, than fixing up/finishing what we have.

So yeah, never wait for something to be completed in D, always expect what you have now is what you have in a couple of years, except for that you can be guaranteed a tons of new half-finished features will be added along with a handful of new attributes that nobody really understands.

December 08, 2021

On Wednesday, 8 December 2021 at 12:05:16 UTC, bauss wrote:

>

On Wednesday, 8 December 2021 at 09:23:41 UTC, Guillaume Piolat wrote:

>

On Tuesday, 7 December 2021 at 16:43:21 UTC, ManKey wrote:

>

I tried this

ldc2 test.i -mixin="test.d"

but the test.d file is empty :(

  • you can do it by hand
  • or instead you can wait a few years that ImportC becomes workable :)

It'll probably be dropped for the next big feature before being finished, just like everything else in D. Nothing is ever completed or workable. Only ever a subset works.

Disagree.
For example SIMD, array ops, DUB improved and transitionned from unusable to workhorse.
Stuff that no one cares about, on the other hand, gets in the limbo zone much longer.

December 08, 2021

On Wednesday, 8 December 2021 at 13:13:05 UTC, Guillaume Piolat wrote:

>

On Wednesday, 8 December 2021 at 12:05:16 UTC, bauss wrote:

>

On Wednesday, 8 December 2021 at 09:23:41 UTC, Guillaume Piolat wrote:

>

On Tuesday, 7 December 2021 at 16:43:21 UTC, ManKey wrote:

>

I tried this

ldc2 test.i -mixin="test.d"

but the test.d file is empty :(

  • you can do it by hand
  • or instead you can wait a few years that ImportC becomes workable :)

It'll probably be dropped for the next big feature before being finished, just like everything else in D. Nothing is ever completed or workable. Only ever a subset works.

Disagree.
For example SIMD, array ops, DUB improved and transitionned from unusable to workhorse.
Stuff that no one cares about, on the other hand, gets in the limbo zone much longer.

I listed things that has been unfinished for like a decade, how can you disagree by just stating a couple of examples that has been done?

I never said everything doesn't get finished. I said that ground-breaking features never gets finished, things that actually matters, like shared is still broken, nogc is still too limited, allocators don't work properly and have been in experimental for years, std.json has never been replaced, same with std.sockets etc. betterC is still somewhat limited, scope has so many bugs/edge cases that hasn't been solved, making it unusable in general. I could list probably a thousand other things where D has neglected existing features for new features.

« First   ‹ Prev
1 2 3