Re: "Error: `TypeInfo` cannot be used with -betterC" on a CTFE function

2024-04-14 Thread Richard (Rikki) Andrew Cattermole via Digitalmars-d-learn
On 15/04/2024 10:36 AM, Liam McGillivray wrote: Well, it did work when I tried it (using a string variable, not a literal of course). It displayed as it is supposed to. But from the information I can find on the web it looks like strings are sometimes but not |always| zero-terminated. Not a

Re: "Error: `TypeInfo` cannot be used with -betterC" on a CTFE function

2024-04-14 Thread Steven Schveighoffer via Digitalmars-d-learn
On Sunday, 14 April 2024 at 22:36:18 UTC, Liam McGillivray wrote: On Friday, 12 April 2024 at 15:24:38 UTC, Steven Schveighoffer wrote: ```d void InitWindow(int width, int height, ref string title) { InitWindow(width, height, cast(const(char)*)title); } ``` This is invalid, a string may

Re: "Error: `TypeInfo` cannot be used with -betterC" on a CTFE function

2024-04-14 Thread Liam McGillivray via Digitalmars-d-learn
On Friday, 12 April 2024 at 15:24:38 UTC, Steven Schveighoffer wrote: ```d void InitWindow(int width, int height, ref string title) { InitWindow(width, height, cast(const(char)*)title); } ``` This is invalid, a string may not be zero-terminated. You can't just cast. Well, it did work

Re: "Error: `TypeInfo` cannot be used with -betterC" on a CTFE function

2024-04-12 Thread Steven Schveighoffer via Digitalmars-d-learn
On Friday, 12 April 2024 at 00:04:48 UTC, Liam McGillivray wrote: Here's what I wanted to do. In the library I'm working on, there are various declarations for functions defined in an external C library following the line `extern (C) @nogc nothrow:`. Here are some examples of such

Re: "Error: `TypeInfo` cannot be used with -betterC" on a CTFE function

2024-04-11 Thread Liam McGillivray via Digitalmars-d-learn
On Tuesday, 9 April 2024 at 12:45:55 UTC, Richard (Rikki) Andrew Cattermole wrote: On 09/04/2024 12:48 PM, Liam McGillivray wrote: I suppose this was a good new thing to learn, though I'm still quite far from being able to construct a function from another function using a template. I

Re: "Error: `TypeInfo` cannot be used with -betterC" on a CTFE function

2024-04-10 Thread Steven Schveighoffer via Digitalmars-d-learn
On Tuesday, 9 April 2024 at 23:50:36 UTC, Richard (Rikki) Andrew Cattermole wrote: On 10/04/2024 11:21 AM, Liam McGillivray wrote: On Sunday, 7 April 2024 at 08:59:55 UTC, Richard (Rikki) Andrew Cattermole wrote: Unfortunately runtime and CTFE are the same target in the compiler. So that

Re: "Error: `TypeInfo` cannot be used with -betterC" on a CTFE function

2024-04-10 Thread Richard (Rikki) Andrew Cattermole via Digitalmars-d-learn
On 10/04/2024 2:50 PM, Liam McGillivray wrote: On Tuesday, 9 April 2024 at 23:50:36 UTC, Richard (Rikki) Andrew Cattermole wrote: The string mixin triggers CTFE, if ``EnumPrefixes`` wasn't templated, that would cause codegen and hence error. If you called it in a context that wasn't CTFE only,

Re: "Error: `TypeInfo` cannot be used with -betterC" on a CTFE function

2024-04-09 Thread Liam McGillivray via Digitalmars-d-learn
On Tuesday, 9 April 2024 at 23:50:36 UTC, Richard (Rikki) Andrew Cattermole wrote: The string mixin triggers CTFE, if ``EnumPrefixes`` wasn't templated, that would cause codegen and hence error. If you called it in a context that wasn't CTFE only, it would codegen even with template and would

Re: "Error: `TypeInfo` cannot be used with -betterC" on a CTFE function

2024-04-09 Thread Richard (Rikki) Andrew Cattermole via Digitalmars-d-learn
On 10/04/2024 11:21 AM, Liam McGillivray wrote: On Sunday, 7 April 2024 at 08:59:55 UTC, Richard (Rikki) Andrew Cattermole wrote: Unfortunately runtime and CTFE are the same target in the compiler. So that function is being used for both, and hence uses GC (appending). Are you sure that

Re: "Error: `TypeInfo` cannot be used with -betterC" on a CTFE function

2024-04-09 Thread Liam McGillivray via Digitalmars-d-learn
On Sunday, 7 April 2024 at 08:59:55 UTC, Richard (Rikki) Andrew Cattermole wrote: Unfortunately runtime and CTFE are the same target in the compiler. So that function is being used for both, and hence uses GC (appending). Are you sure that string appending was really the problem that

Re: "Error: `TypeInfo` cannot be used with -betterC" on a CTFE function

2024-04-09 Thread Richard (Rikki) Andrew Cattermole via Digitalmars-d-learn
On 09/04/2024 12:48 PM, Liam McGillivray wrote: On Tuesday, 9 April 2024 at 00:02:02 UTC, Richard (Rikki) Andrew Cattermole wrote: ```d enum Value = (a, b) { return a + b; }(1, 2); ``` This alone should be a CTFE only function. But if we want template parameters, we'd need to wrap it

Re: "Error: `TypeInfo` cannot be used with -betterC" on a CTFE function

2024-04-09 Thread Kagamin via Digitalmars-d-learn
On Sunday, 7 April 2024 at 06:46:39 UTC, Liam McGillivray wrote: instantiated from here: `front!char` Looks like autodecoding, try to comment `canFind`.

Re: "Error: `TypeInfo` cannot be used with -betterC" on a CTFE function

2024-04-08 Thread Liam McGillivray via Digitalmars-d-learn
On Tuesday, 9 April 2024 at 00:02:02 UTC, Richard (Rikki) Andrew Cattermole wrote: ```d enum Value = (a, b) { return a + b; }(1, 2); ``` This alone should be a CTFE only function. But if we want template parameters, we'd need to wrap it with the template. ```d template Value(int a,

Re: "Error: `TypeInfo` cannot be used with -betterC" on a CTFE function

2024-04-08 Thread Richard (Rikki) Andrew Cattermole via Digitalmars-d-learn
On 09/04/2024 11:42 AM, Liam McGillivray wrote: On Monday, 8 April 2024 at 08:12:22 UTC, Richard (Rikki) Andrew Cattermole wrote: ```d template Foo(Args) { enum Foo = () {     return Args.init; }(); } ``` Something like that should work instead. I'm sorry, but I can't

Re: "Error: `TypeInfo` cannot be used with -betterC" on a CTFE function

2024-04-08 Thread Liam McGillivray via Digitalmars-d-learn
On Monday, 8 April 2024 at 08:12:22 UTC, Richard (Rikki) Andrew Cattermole wrote: ```d template Foo(Args) { enum Foo = () {     return Args.init; }(); } ``` Something like that should work instead. I'm sorry, but I can't comprehend any of your example. What would be fed into

Re: "Error: `TypeInfo` cannot be used with -betterC" on a CTFE function

2024-04-08 Thread Richard (Rikki) Andrew Cattermole via Digitalmars-d-learn
On 08/04/2024 10:45 AM, Liam McGillivray wrote: On Sunday, 7 April 2024 at 08:59:55 UTC, Richard (Rikki) Andrew Cattermole wrote: Unfortunately runtime and CTFE are the same target in the compiler. :-( Will this ever be changed? A tad unlikely, it would be a rather large change

Re: "Error: `TypeInfo` cannot be used with -betterC" on a CTFE function

2024-04-07 Thread Liam McGillivray via Digitalmars-d-learn
On Sunday, 7 April 2024 at 08:59:55 UTC, Richard (Rikki) Andrew Cattermole wrote: Unfortunately runtime and CTFE are the same target in the compiler. :-( Will this ever be changed? ```d template Foo(Args) { enum Foo = () { return Args.init; }(); } ```

Re: "Error: `TypeInfo` cannot be used with -betterC" on a CTFE function

2024-04-07 Thread Richard (Rikki) Andrew Cattermole via Digitalmars-d-learn
Unfortunately runtime and CTFE are the same target in the compiler. So that function is being used for both, and hence uses GC (appending). ```d template Foo(Args) { enum Foo = () { return Args.init; }(); } ``` Something like that should work instead.