[Issue 6232] An idea for std.string.toStringz docs

d-bugmail at puremagic.com d-bugmail at puremagic.com
Thu Jun 30 19:02:46 PDT 2011


http://d.puremagic.com/issues/show_bug.cgi?id=6232



--- Comment #4 from bearophile_hugs at eml.cc 2011-06-30 18:57:48 PDT ---
(In reply to comment #3)
> Your suggestion doesn't help at all with remembering to use zero-terminated
> strings when calling C code.

> Are your
> suggestion only helps as far as the type system goes if all of the C functions
> in druntime or wherever use CcharPtr instead of char*, since if the function
> takes char*, you can still pass a string directly to them even if you have
> CcharPtr to use if you want to. So, I don't see how this suggestion helps much
> of anything.

With extern(C) you are free to give to C functions a signature that you want.

In this example strlen() is meant as an example of random user-defined function
from some third-party C lib. Maybe using strlen() is not a clear enough
example, I have to use the frobaz() C function instead.

The idea here is that you define their signature using something like CcharPtr.
If you do this, the type system will catch your bugs because you can't pass a
char* to those C functions.

Similar tricks, or ones based on more complex type system features, allow you
to kill bugs in F# code, ATS code, etc.

-- 
Configure issuemail: http://d.puremagic.com/issues/userprefs.cgi?tab=email
------- You are receiving this mail because: -------


More information about the Digitalmars-d-bugs mailing list