I don't understand betterC

Richard (Rikki) Andrew Cattermole richard at cattermole.co.nz
Thu Aug 31 18:42:57 UTC 2023


```d
extern(C) int main()
{
     import core.stdc.stdio;

     string hello = "hello";
     printf(hello.ptr);

     return 0;
}
```

1) You forgot to import ``core.stdc.stdio``
2) String literal is of type string (which is an alias to 
``immutable(char)[]``).
3) A slice is a pointer + length, and C doesn't understand slices, so 
you must explicitly pass in the pointer from the slice (the compiler 
would do this for you if you had the literal in the arguments list 
instead of the variable).


More information about the Digitalmars-d-learn mailing list