opendlang / opend

Boost Software License 1.0
84 stars 18 forks source link

Enable C preprocessing for .i files? #72

Closed denizzzka closed 4 months ago

denizzzka commented 4 months ago

What do you think about this? - https://github.com/dlang/dmd/pull/16386

(I use ldc2 so the option of including mentioned PR into this compiler would suit me)

adamdruppe commented 4 months ago

I don't really know, what's the use case here? I don't use import c at all so i don't really know.

you have something like a makefile that makes the .is? if so can't that add the importc.h to them so it spits out in a format dmd can use?

adamdruppe commented 4 months ago

I guess the real question is what would break if this was enabled?

denizzzka commented 4 months ago

I guess the real question is what would break if this was enabled?

Nothing should break, because for now correct *.i files is strictly corresponding to C11 standard, so preprocessor will not change these files by applying importc.h

adamdruppe commented 4 months ago

huh. well we might as well do it then i don't really care either way so if it is useful to you and nobody else cites breakage i'd allow it

denizzzka commented 4 months ago

I don't really know, what's the use case here? I don't use import c at all so i don't really know.

importC is straight way to create bindings to C. It can be very useful, at least, in case of embedded programming for MCUs, because 99% of MCU software (libaries, OSes) is written on C.

you have something like a makefile that makes the .is?

Only in theory

In practice, almost all build systems (and infrastructure for embedded compilation) isn't provide ways to create *.i files and then parse it and then build and link with D object files. Every additional step in this list is hurts. (I think it is because almost all C coders really just not know or forgot about preprocessed files at all)

if so can't that add the importc.h to them so it spits out in a format dmd can use?

Yes, this turns out to be one of the mandatory additional steps to convert (an externally created) .i file into C11 which needed by D compiler. This is the step I'm trying to avoid by mentioned PR.

Taking into account the fact that there are no pure C11 source codes in the World at all (Pardon me for this generalization?), demanding of strictly corresponding to C11 for *.i files becomes meaningless - as well as for .c files, but .c files converted implicitely by D compiler

denizzzka commented 4 months ago

At present, I have no need this functionality. If someone will do it, please, write. Or I will do it later when I need it.