[Issue 7854] Non-C attributes allowed on extern(C) function parameters

d-bugmail at puremagic.com d-bugmail at puremagic.com
Thu Oct 26 06:48:01 UTC 2017


https://issues.dlang.org/show_bug.cgi?id=7854

Walter Bright <bugzilla at digitalmars.com> changed:

           What    |Removed                     |Added
----------------------------------------------------------------------------
             Status|NEW                         |RESOLVED
                 CC|                            |bugzilla at digitalmars.com
         Resolution|---                         |INVALID

--- Comment #15 from Walter Bright <bugzilla at digitalmars.com> ---
This is actually a feature. I used it to good effect to define a function for
errno:

https://github.com/dlang/druntime/blob/master/src/core/stdc/errno.d#L34

    extern (C)
    {
        ref int _errno();
        alias errno = _errno;
    }

The actual function in the C runtime library returns an int*, but by making it
a ref int it will automatically dereference in D, enabling the simple use of
`errno` as in C.

Other uses are being able to hook up to functions based on their underlying
representation and bypass the stronger type checking D has. Such as FILE is a
shared type in D, but in C it's just another type. Sending it as extern(C) is
very convenient.

--


More information about the Digitalmars-d-bugs mailing list