www.digitalmars.com         C & C++   DMDScript  

digitalmars.D.bugs - =?UTF-8?B?W0lzc3VlIDI0MTU4XSBOZXc6IEltcG9ydEM6IGVudW1zIGNyZWF0?=

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 puremagic.com
          Reporter: dave287091 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`

--
Sep 25 2023