Jump to page: 1 24  
Page
Thread overview
Is importC ready?
Nov 09, 2021
bachmeier
Nov 09, 2021
Tejas
Nov 09, 2021
bachmeier
Nov 09, 2021
Imperatorn
Nov 09, 2021
Dave P.
Nov 09, 2021
bachmeier
Nov 10, 2021
WebFreak001
Nov 10, 2021
Dave P.
Nov 10, 2021
bachmeier
Nov 09, 2021
Dave P.
Nov 11, 2021
Walter Bright
Nov 11, 2021
SealabJaster
Nov 11, 2021
bachmeier
Nov 11, 2021
bachmeier
Nov 11, 2021
bachmeier
Nov 11, 2021
bachmeier
Nov 12, 2021
Walter Bright
Nov 12, 2021
Walter Bright
Nov 12, 2021
Dave P.
Nov 12, 2021
Walter Bright
Nov 12, 2021
bachmeier
Nov 16, 2021
Walter Bright
Nov 17, 2021
Walter Bright
[Solved] Re: Is importC ready?
Nov 15, 2021
bachmeier
Nov 18, 2021
bachmeier
Nov 19, 2021
Walter Bright
Nov 18, 2021
bachmeier
Nov 18, 2021
Paulo Pinto
Nov 16, 2021
surlymoor
November 09, 2021

I tried to compile a simple C file this morning, containing

#include "nmath.h"

double fsign(double x, double y)
{
#ifdef IEEE_754
    if (ISNAN(x) || ISNAN(y))
	return x + y;
#endif
    return ((y >= 0) ? fabs(x) : -fabs(x));
}

I assumed this would be straightforward since it doesn't have a bunch of dependencies and it's only a few lines of code. Instead, I got a stream of errors. After running the file through the preprocessor, I had to comment out anything with

  • __extension__
  • Restricted pointers *__restrict
  • _Float128
  • __asm__

And in the source, anything with ISNAN, or in the preprocessed file,

  • __builtin_isnan

I filed a bug. After this experience, it's not obvious to me that importC is ready to be part of a stable compiler release. Maybe I just had bad luck with the choice of file.

November 09, 2021

On Tuesday, 9 November 2021 at 16:41:04 UTC, bachmeier wrote:

>

I tried to compile a simple C file this morning, containing

#include "nmath.h"

double fsign(double x, double y)
{
#ifdef IEEE_754
    if (ISNAN(x) || ISNAN(y))
	return x + y;
#endif
    return ((y >= 0) ? fabs(x) : -fabs(x));
}

I assumed this would be straightforward since it doesn't have a bunch of dependencies and it's only a few lines of code. Instead, I got a stream of errors. After running the file through the preprocessor, I had to comment out anything with

  • __extension__
  • Restricted pointers *__restrict
  • _Float128
  • __asm__

And in the source, anything with ISNAN, or in the preprocessed file,

  • __builtin_isnan

I filed a bug. After this experience, it's not obvious to me that importC is ready to be part of a stable compiler release. Maybe I just had bad luck with the choice of file.

It looks like that file uses a lot of compiler extensions

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

ImportC only compiles standard C11 and nothing more

(Although that noreturn part might need updating since we have that now, i think)

November 09, 2021

On Tuesday, 9 November 2021 at 16:41:04 UTC, bachmeier wrote:

>

I tried to compile a simple C file this morning, containing

#include "nmath.h"

double fsign(double x, double y)
{
#ifdef IEEE_754
    if (ISNAN(x) || ISNAN(y))
	return x + y;
#endif
    return ((y >= 0) ? fabs(x) : -fabs(x));
}

I assumed this would be straightforward since it doesn't have a bunch of dependencies and it's only a few lines of code. Instead, I got a stream of errors. After running the file through the preprocessor, I had to comment out anything with

  • __extension__
  • Restricted pointers *__restrict
  • _Float128
  • __asm__

And in the source, anything with ISNAN, or in the preprocessed file,

  • __builtin_isnan

I filed a bug. After this experience, it's not obvious to me that importC is ready to be part of a stable compiler release. Maybe I just had bad luck with the choice of file.

It can parse simple C files, but IMO is not ready yet. There are still a number of outstanding bugs that should be resolved before declaring it “ready”.

November 09, 2021

On Tuesday, 9 November 2021 at 17:14:52 UTC, Tejas wrote:

>

On Tuesday, 9 November 2021 at 16:41:04 UTC, bachmeier wrote:

>

I tried to compile a simple C file this morning, containing

#include "nmath.h"

double fsign(double x, double y)
{
#ifdef IEEE_754
    if (ISNAN(x) || ISNAN(y))
	return x + y;
#endif
    return ((y >= 0) ? fabs(x) : -fabs(x));
}

I assumed this would be straightforward since it doesn't have a bunch of dependencies and it's only a few lines of code. Instead, I got a stream of errors. After running the file through the preprocessor, I had to comment out anything with

  • __extension__
  • Restricted pointers *__restrict
  • _Float128
  • __asm__

And in the source, anything with ISNAN, or in the preprocessed file,

  • __builtin_isnan

I filed a bug. After this experience, it's not obvious to me that importC is ready to be part of a stable compiler release. Maybe I just had bad luck with the choice of file.

It looks like that file uses a lot of compiler extensions

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

ImportC only compiles standard C11 and nothing more

(Although that noreturn part might need updating since we have that now, i think)

It doesn't seem practical to ignore compiler extensions and leave them to the user to debug and fix. My understanding is that you can convert restricted pointers *__restrict to a simple * - the compiler should recognize that and make the change for you. At a minimum, the compiler knows when it's encountering extensions and can spit out a message telling you what's going on. The current messages are pretty awful.

November 09, 2021

On Tuesday, 9 November 2021 at 18:45:04 UTC, bachmeier wrote:

>

On Tuesday, 9 November 2021 at 17:14:52 UTC, Tejas wrote:

>

[...]

It doesn't seem practical to ignore compiler extensions and leave them to the user to debug and fix. My understanding is that you can convert restricted pointers *__restrict to a simple * - the compiler should recognize that and make the change for you. At a minimum, the compiler knows when it's encountering extensions and can spit out a message telling you what's going on. The current messages are pretty awful.

Imo we should try to fix that. Let's hope Walter agrees 🍀

November 09, 2021

On Tuesday, 9 November 2021 at 18:45:04 UTC, bachmeier wrote:

>

On Tuesday, 9 November 2021 at 17:14:52 UTC, Tejas wrote:

>

On Tuesday, 9 November 2021 at 16:41:04 UTC, bachmeier wrote:

>

I tried to compile a simple C file this morning, containing
[...]
It doesn't seem practical to ignore compiler extensions and leave them to the user to debug and fix. My understanding is that you can convert restricted pointers *__restrict to a simple * - the compiler should recognize that and make the change for you. At a minimum, the compiler knows when it's encountering extensions and can spit out a message telling you what's going on. The current messages are pretty awful.

ImportC understands restrict, it just doesn’t understand non-standard keywords. See this.

That example is incomplete, but you can #define __restrict restrict, #define __asm__ asm, etc.

I agree that the error messages suck.

November 09, 2021

On Tuesday, 9 November 2021 at 19:04:04 UTC, Dave P. wrote:

>

On Tuesday, 9 November 2021 at 18:45:04 UTC, bachmeier wrote:

>

On Tuesday, 9 November 2021 at 17:14:52 UTC, Tejas wrote:

>

On Tuesday, 9 November 2021 at 16:41:04 UTC, bachmeier wrote:

>

I tried to compile a simple C file this morning, containing
[...]
It doesn't seem practical to ignore compiler extensions and leave them to the user to debug and fix. My understanding is that you can convert restricted pointers *__restrict to a simple * - the compiler should recognize that and make the change for you. At a minimum, the compiler knows when it's encountering extensions and can spit out a message telling you what's going on. The current messages are pretty awful.

ImportC understands restrict, it just doesn’t understand non-standard keywords. See this.

That example is incomplete, but you can #define __restrict restrict, #define __asm__ asm, etc.

I agree that the error messages suck.

Yeah, I saw that example, but the main limitation of such a strategy is that I don't have the knowledge to construct a file that without potentially changing behavior. I made some changes by hand and confirmed that changing *__restrict to *restrict, __asm__ to asm, and buitin_isnan to isnan results in a file that compiles. That still leaves _Float128. This all requires a lot of C compiler knowledge that shouldn't be required of a D programmer.

November 10, 2021

On Tuesday, 9 November 2021 at 19:04:04 UTC, Dave P. wrote:

>

On Tuesday, 9 November 2021 at 18:45:04 UTC, bachmeier wrote:

>

[...]

ImportC understands restrict, it just doesn’t understand non-standard keywords. See this.

That example is incomplete, but you can #define __restrict restrict, #define __asm__ asm, etc.

I agree that the error messages suck.

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

>

The restrict type-qualifier (C11 6.7.3) is ignored

November 10, 2021

On Wednesday, 10 November 2021 at 15:42:52 UTC, WebFreak001 wrote:

>

On Tuesday, 9 November 2021 at 19:04:04 UTC, Dave P. wrote:

>

On Tuesday, 9 November 2021 at 18:45:04 UTC, bachmeier wrote:

>

[...]

ImportC understands restrict, it just doesn’t understand non-standard keywords. See this.

That example is incomplete, but you can #define __restrict restrict, #define __asm__ asm, etc.

I agree that the error messages suck.

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

>

The restrict type-qualifier (C11 6.7.3) is ignored

That is a conformant implementation of restrict. Restrict is just an optimization hint.

>

The intended use of the restrict qualifier (like the register storage class) is to promote optimization, and deleting all instances of the qualifier from all preprocessing translation units composing a conforming program does not change its meaning (i.e., observable behavior).

By “understand” I mean it recognizes it as a keyword and that it is a type qualifier.

November 10, 2021

On Wednesday, 10 November 2021 at 15:42:52 UTC, WebFreak001 wrote:

>

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

>

The restrict type-qualifier (C11 6.7.3) is ignored

And it should be added to that page that you'll get strange error messages like Error: illegal combination of type specifiers when you try to compile C code with *__restrict buried in line 874. Wouldn't be difficult to print a warning saying restrict was ignored and which line.

« First   ‹ Prev
1 2 3 4