I don't understand betterC

confused no at no.no
Fri Sep 1 01:49:02 UTC 2023


On Thursday, 31 August 2023 at 18:42:57 UTC, Richard (Rikki) 
Andrew Cattermole wrote:
> ```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).

```d
import core.stdc.stdio;
```

This generates ``` Error: undefined identifier `size_t` ```.


More information about the Digitalmars-d-learn mailing list