Add ImportC compiler to dmd
Brian
bcallah at openbsd.org
Mon May 10 01:50:40 UTC 2021
On Monday, 10 May 2021 at 01:13:25 UTC, Max Haughton wrote:
> ```
> #include <stdio.h>
> inline int square(int num) {
> return num * num;
> }
>
> int main()
> {
> printf("%d\n", square(3));
> }
> ```
> fails to link in C but not in C++.
>
Whether or not your code links in C depends on a number of
factors. It is not as simple as you make it out to be.
Consider on my OpenBSD machine:
```
/home/brian/c $ gcc --version
gcc (GCC) 12.0.0 20210421 (experimental)
Copyright (C) 2021 Free Software Foundation, Inc.
This is free software; see the source for copying conditions.
There is NO
warranty; not even for MERCHANTABILITY or FITNESS FOR A
PARTICULAR PURPOSE.
/home/brian/c $ gcc -o square square.c
ld: error: undefined symbol: square
>>> referenced by square.c
>>> /tmp//cc3wDuve.o:(main)
collect2: error: ld returned 1 exit status
/home/brian/c $ gcc -O2 -o square square.c
/home/brian/c $ ./square
9
```
~Brian
More information about the Digitalmars-d
mailing list