A Programmer's Dilema: juggling with C, BetterC, D, Macros and Cross Compiling, etc.

Eric P626 ericp at lariennalibrary.com
Mon May 1 09:17:14 UTC 2023


> This is a false dilemma: D has full C compatibility.

 From what I understand, D can use C, but C cannot use D? It's 
like C++: C++ can call C but C cannot call C++.

50% or more of my code will be put in re-usabled libraries. If I 
want people to use those libs, I would need to compile them in C 
or better C. Because betterC seems to create C libraries. If D 
can make C libraries, then indeed, I could do everything in D.

> You could use BetterC for sure, but it's more practical in the 
> long term to just learn to live with the GC: it is a one-time 
> mental cost.

I think I can live with the GC because it's not going to get 
called often in the end since I mostly use memory pre-allocation. 
You allocate everything on program start, and free it all on 
program's end. I am also not doing realtime games, so no 
possibility of lagging during animations.

The main issues seems portability and cross compiling.

> The consensus is to use DMD for fast compiles and then use LDC 
> for your optimized release builds (LLVM is unmatched for 
> optimizations, LDC is our savior)

Interesting, I found this page that seems to document it.

https://wiki.dlang.org/Cross-compiling_with_LDC

Lot of platforms seems available. Seems also compatible with 
Cmake which I am already using. I would need to make some build 
tests.

I'll have to see how Allegro, SDL and Sqlite can be integrated, 
one issue with cross compiling is that I need to have an library 
file compiled with Mingw for cross compiling and the regular lib 
for gcc building. If I could use the same lib for all platforms, 
that would be awesome.

> C++ is essentially C .. plus.. you get 'selective' access to 
> any and all the features of C++, should you ever decide some 
> are actually useful in your projects.

Sure, I could select a subset of the C++ language, and only 
benefit from those features. For example, I could have 
constructors for structs. But C++ is a language that tries to 
implement features the most convoluted way. You can end up with 
very complex error messages hard to analyze (very long variable 
types), hidden bugs hard to detect (ex: implicit function calls) 
and very complex syntax. So by restraining it to C, you remove 
all the possible crap that C++ can inject making it easier to 
program.

Sure if betterC has not much to offer, or if it's buggy, then 
maybe the choice will be between C and D. If LDC could indeed 
make cross-compiling easier that Mingw and Gcc, that would be a 
good reason to switch.

Is there a detailed list of the features you get in betterC?

I found this page that gives the list, but it's pretty vague:

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

There is a make-over example here:

https://dlang.org/blog/category/betterc/

There is an interesting D for C programmers page

https://dlang.org/articles/ctod.html

But it seems to include more than the betterC features.

Now that you mention raylib ... it looks awesome. According to 
this cheatsheet:

https://www.raylib.com/cheatsheet/cheatsheet.html

It looks relatively accessible. Like Allegro, it's just a bunch 
of functions to call. It seems to support 3d polygons which I 
need for the maze engine, and have bitmap text support which I 
also need for the user interface. SDL did not have 3D polygons, 
and text support was limited. As for Allegro, I was stuck with 
the old Allegro 4 to get 3D polygons.

I makes me strongly consider switching library since Allegro 4 is 
old. Seems I have more research and testing to do.

... By the way, how do you change your avatar on this forum? 
There is no options on the settings page.


More information about the Digitalmars-d-learn mailing list