On 30/04/2018 2:42 AM, dd886k wrote:
Hello!

This is my first time posting, so do feel free to correct me and this post.

I started writing in D around Q2 2017 and recently been re-writing some of my projects as betterC (entirely!).

I noticed something weird. It started with DMD 2.074.0 and it's still an issue for me in DMD 2.079.1 (and any other compiler really).

Consider this piece:

```
import core.stdc.stdio;

extern(C) void main() {
     printf("a");
}
```

It compiles and runs absolutely wonderful (OMF, MSCOFF, ELF, etc.). No issues.

Now consider this piece:

```
import core.stdc.stdio;

extern(C) void main() {
     putchar('a');
}
```

Oops, `Error 42: Symbol Undefined __D4core4stdc5stdio7putcharFNbNiNeiZi`! To my surprise, `putchar` is extern'd as D in druntime/src/core/stdc/stdio.d, and I find that _really silly_.

Which means `putchar`, during linking, is affected for linking every single C runtime out there, and the only reason I can think of is to easily integrate it with D in general, which in my opinion, is not necessarily needed since the D people (not meant as an insult) promotes betterC as a stand-alone option.

On Windows, stdin, stdout, and stderr are affected when using -m32mscoff and -m64 (and obviously, LDC) because under CRuntime_Microsoft, std* are defined as `shared`.

I'm aware that an easy solution would be defining a version (D_betterC) section.

Will I do a Pull Request? Unfortunately no, I fear I'll abandon mid-way through. It's easier to advise the forums and let an actual professional integrate the fix.

If you have other suggestions, I'm all ears.

Welcome.

I just checked, extern(D) isn't at fault. You actually do want name mangling for wrapper functions like that.

Did you only -I the file? If you compile it in normally, it won't error out. Normally its compiled into druntime and hence Phobos.

We really should have functions like this be templated (empty brackets) so that it'll work with just -I happily.

Reply via email to