[Issue 24158] New: ImportC: enums created from string literal #defines don’t implicitly convert to const(char)* in D.
d-bugmail at puremagic.com
d-bugmail at puremagic.com
Mon Sep 25 22:12:15 UTC 2023
https://issues.dlang.org/show_bug.cgi?id=24158
Issue ID: 24158
Summary: ImportC: enums created from string literal #defines
don’t implicitly convert to const(char)* in D.
Product: D
Version: D2
Hardware: All
OS: All
Status: NEW
Keywords: ImportC
Severity: normal
Priority: P1
Component: dmd
Assignee: nobody at puremagic.com
Reporter: dave287091 at gmail.com
Following D code works fine:
enum X = "X";
import core.stdc.stdio;
void main(){
puts(X);
}
However, if that enum X is the result of a #define in a C file, you get an
error:
// x.c
#define X “X”
// D code
import x;
import core.stdc.stdio;
void main(){
puts(X); // Error
}
// Error: function `core.stdc.stdio.puts(scope const(char*) s)` is not
callable using argument types `(char[2])`
// cannot pass argument `"X"` of type `char[2]` to parameter `scope
const(char*) s`
--
More information about the Digitalmars-d-bugs
mailing list