I'm writing CTFE on Windows, latest DMD compiler. How should I write a message to the console (stderr) from a CTFE function call during compilation?
Thread overview | |||||||||||||
---|---|---|---|---|---|---|---|---|---|---|---|---|---|
|
April 04 CTFE write message to console | ||||
---|---|---|---|---|
| ||||
April 05 Re: CTFE write message to console | ||||
---|---|---|---|---|
| ||||
Posted in reply to Carl Sturtivant | On 05/04/2024 2:54 AM, Carl Sturtivant wrote:
> I'm writing CTFE on Windows, latest DMD compiler. How should I write a message to the console (stderr) from a CTFE function call during compilation?
```d
static assert(0, "message");
```
Or if it is known to be CTFE'd
```d
assert(0, "message");
```
Just a warning, its a one time use only for both.
No other way to do it.
|
April 04 Re: CTFE write message to console | ||||
---|---|---|---|---|
| ||||
Posted in reply to Richard (Rikki) Andrew Cattermole | On Thursday, 4 April 2024 at 14:06:19 UTC, Richard (Rikki) Andrew Cattermole wrote: >
Or if it is known to be CTFE'd
Just a warning, its a one time use only for both. No other way to do it. That's ... unfortunate. Some search of the forum led me to some decade plus old discussion of a possible CTFE writeln function that would be a no-op at runtime, which to my surprise led me to find core_builtins.__ctfeWrite but when I tried it out, it compiled yet output no text to the console. Given your remarks I suppose I should have expected this. |
April 05 Re: CTFE write message to console | ||||
---|---|---|---|---|
| ||||
Posted in reply to Carl Sturtivant |
On 05/04/2024 4:04 AM, Carl Sturtivant wrote:
> On Thursday, 4 April 2024 at 14:06:19 UTC, Richard (Rikki) Andrew Cattermole wrote:
>>
>> ```d
>> static assert(0, "message");
>> ```
>>
>> Or if it is known to be CTFE'd
>>
>> ```d
>> assert(0, "message");
>> ```
>>
>> Just a warning, its a one time use only for both.
>>
>> No other way to do it.
>
> That's ... unfortunate.
>
> Some search of the forum led me to some [decade plus old discussion](https://forum.dlang.org/post/j1n1m2$24p0$1@digitalmars.com) of a possible CTFE writeln function that would be a no-op at runtime, which to my surprise led me to find [core_builtins.__ctfeWrite](https://dlang.org/phobos/core_builtins.html#.__ctfeWrite) but when I tried it out, it compiled yet output no text to the console. Given your remarks I suppose I should have expected this.
Ah yes, I forgot about that particular thing, doesn't see much use as far as I'm aware.
It should be working though.
|
April 04 Re: CTFE write message to console | ||||
---|---|---|---|---|
| ||||
Posted in reply to Richard (Rikki) Andrew Cattermole | On Thursday, 4 April 2024 at 15:07:21 UTC, Richard (Rikki) Andrew Cattermole wrote: >Ah yes, I forgot about that particular thing, doesn't see much use as far as I'm aware. It should be working though.
Produces no output on compilation, and writes out |
April 05 Re: CTFE write message to console | ||||
---|---|---|---|---|
| ||||
Posted in reply to Carl Sturtivant | Oh hey! https://github.com/dlang/dmd/pull/16250 It was implemented literally 2 weeks ago! Nightly should have it https://github.com/dlang/dmd/releases/tag/nightly |
April 04 Re: CTFE write message to console | ||||
---|---|---|---|---|
| ||||
Posted in reply to Richard (Rikki) Andrew Cattermole | On Thursday, 4 April 2024 at 15:47:53 UTC, Richard (Rikki) Andrew Cattermole wrote:
> Oh hey!
>
> https://github.com/dlang/dmd/pull/16250
>
> It was implemented literally 2 weeks ago!
>
> Nightly should have it https://github.com/dlang/dmd/releases/tag/nightly
Wow! Happy that's in. It was a bit mysterious, but now that request says it was never implemented. Until now. Just what I want!
|
April 04 Re: CTFE write message to console | ||||
---|---|---|---|---|
| ||||
Posted in reply to Richard (Rikki) Andrew Cattermole | On Thursday, 4 April 2024 at 15:47:53 UTC, Richard (Rikki) Andrew Cattermole wrote:
> Oh hey!
>
> https://github.com/dlang/dmd/pull/16250
>
> It was implemented literally 2 weeks ago!
>
> Nightly should have it https://github.com/dlang/dmd/releases/tag/nightly
Good news, thanks...
SDB@79
|
April 05 Re: CTFE write message to console | ||||
---|---|---|---|---|
| ||||
Posted in reply to Carl Sturtivant | On Thursday, 4 April 2024 at 15:43:55 UTC, Carl Sturtivant wrote: >On Thursday, 4 April 2024 at 15:07:21 UTC, Richard (Rikki) Andrew Cattermole wrote: >Ah yes, I forgot about that particular thing, doesn't see much use as far as I'm aware. It should be working though.
Produces no output on compilation, and writes out pragma(msg, x) ? |
April 05 Re: CTFE write message to console | ||||
---|---|---|---|---|
| ||||
Posted in reply to Paolo Invernizzi | On Friday, 5 April 2024 at 07:37:20 UTC, Paolo Invernizzi wrote: >pragma(msg, x) ? No.
It is defined to output the computed text So it is a replacement for
It is possible that |