View previous topic :: View next topic |
Author |
Message |
sean
Joined: 24 Jun 2004 Posts: 609 Location: Bay Area, CA
|
Posted: Wed Oct 27, 2004 6:27 pm Post subject: C Bindings |
|
|
I've written complete C99 bindings for D, they're available here:
http://home.f4.ca/sean/d/stdc.zip
I've left out the headers that don't make sense, and carried over DMC/DMD stuff when necessary/appropriate (copyrights preserved in headers that borrow stuff from DigitalMars, even if it's just a line of code). The files should include pretty much all the standard C99 stuff (some of it tested) and do not include basically any nonstandard functions (alloca being a notable exception).
I am going to write unit tests for these and would like to do some platform-specific headers as well, such as process.h on Win32 and unistd.h for Unix. I would certainly appreciate feedback if folks can spot problems, etc. I am hoping that these files can become a part of Ares and should ultimately not be tied to any specific compiler (so more versioning will be needed in the future).
I imagine any standard library will probably conceal most of this stuff behind D functions, much like std.math wraps std.c.math in Phobos, but it seemed a good idea to have all the C stuff available.
If people bang on this and all seems kosher I may send them off to Walter and see if he's keen on ddropping them into Phobos as well. |
|
Back to top |
|
|
sean
Joined: 24 Jun 2004 Posts: 609 Location: Bay Area, CA
|
Posted: Thu Oct 28, 2004 9:23 am Post subject: |
|
|
Just a quick note. I edited signal.d to separate out the standard C signals from the POSIX signals, and the POSIX signals are now in a version(POSIX) block. This should probably become another standard version identifier, unless it makes sense to split it further for different subsets of POSIX support. |
|
Back to top |
|
|
sean
Joined: 24 Jun 2004 Posts: 609 Location: Bay Area, CA
|
Posted: Thu Oct 28, 2004 1:12 pm Post subject: |
|
|
I decided to do away with the use of aliases in the header files, so now anything that expects wchar_t or wint_t is declared to accept wchar. The alises just got too confusing and weren't particularly useful. wchar_t and NULL are still defined in stddef, but I don't expect anyone to actually use them. Also, the stuff in wchar.h has been spread out among the other headers (since wchar is a keyword and a module can't have that name). So the i/o stuff is in stdio, the string stuff is in string, etc. I'm just getting started on unistd and such, but I don't know how far I'll get as my only resource for this info is a BSD machine (plus web searches) and I may not be able to figure out some of the required constants and types. If there are any linux folks out there willing to help, please let me know.
(edit)
I reinstated the whcar_t and wint_t aliases on friday--I'd forgotten that Unix uses 32-bit wide chars and Windows uses 16-bit wide chars. Darn vague C spec.
Last edited by sean on Mon Nov 01, 2004 3:10 pm; edited 1 time in total |
|
Back to top |
|
|
qbert
Joined: 30 Mar 2004 Posts: 209 Location: Dallas, Texas
|
Posted: Fri Oct 29, 2004 4:44 pm Post subject: |
|
|
I have a linux box here Ill check it out.
Carlos |
|
Back to top |
|
|
kris
Joined: 27 Mar 2004 Posts: 1494 Location: South Pacific
|
Posted: Fri Oct 29, 2004 5:22 pm Post subject: C99 bindings |
|
|
Hey ... that's useful! |
|
Back to top |
|
|
sean
Joined: 24 Jun 2004 Posts: 609 Location: Bay Area, CA
|
Posted: Mon Nov 01, 2004 3:25 pm Post subject: |
|
|
Thanks a bunch. If you have a copy of sys/types.h that you can post the relevant lines of that would be very helpful as well. I think unistd.h is pretty well sorted, but I still don't have some of the aliases it relies on.
By the way, I updated the lib stuff on friday to use wchar_t aliases. If the version you've got doesn't use them you may want to re-download. |
|
Back to top |
|
|
qbert
Joined: 30 Mar 2004 Posts: 209 Location: Dallas, Texas
|
Posted: Mon Nov 01, 2004 5:29 pm Post subject: |
|
|
Ok cool,
A couple of problems using .105 with 'long int' s and 'long double's also functions named creal, i just changed to D types using http://www.digitalmars.com/d/ctod.html as a guide. Not sure how to handle the creal function in complex.d:79 ?
Also GCC doesn't fully suport C99 yet ( http://gcc.gnu.org/gcc-3.4/c99status.html ) , getting link once linker errors about functions with the same name ( I guess function overloading is part of C99 ? ). Working on types.h now.
Charlie |
|
Back to top |
|
|
sean
Joined: 24 Jun 2004 Posts: 609 Location: Bay Area, CA
|
Posted: Mon Nov 01, 2004 6:23 pm Post subject: |
|
|
qbert wrote: | Ok cool,
A couple of problems using .105 with 'long int' s and 'long double's also functions named creal, i just changed to D types using http://www.digitalmars.com/d/ctod.html as a guide. Not sure how to handle the creal function in complex.d:79 ?
|
The copy of complex.d I have locally only has 75 lines. Are you sure you have the latest set of files? And every instance of "long int" should be "int" while every instance of "long double" should be "real." If you've found some I missed, please let me know.
Quote: |
Also GCC doesn't fully suport C99 yet ( http://gcc.gnu.org/gcc-3.4/c99status.html ) , getting link once linker errors about functions with the same name ( I guess function overloading is part of C99 ? ). Working on types.h now.
|
Yeah I think C99 supports overloading, though it may be in some odd way--math.d has some "overloaded" functions, but they're implemented via macros in the compilers I've looked at. I'll admit I haven't read the spec too closely in this regard. In any case, I used the DMC implementation for the Win32 side, but just left the declarations for the Linux side, so some work will likely need to be done to get all this sorted out. Look at the top 1/3 of math.d to see what I'm talking about.
By the way, the C99 spec says that complex numbers have to be stored in memory like so:
struct cdouble {
double, real, imaginary;
}
It looks like D has the same requirement, so the complex numbers in D *should* just convert automatically to C99 complex numbers, but I haven't tested these functions yet (I will try to do this in the next day or so--I still need to diff the new .105 Phobos lib and see if I need to update anything). And while DMC has complex number support, I am not surprised that GCC does not. I expect more stuff will have to be put into version blocks. I thought about using "DigitalMars" but I assumed this flag would be set for both Windows and Linux right now, since both use the DM front end (?).
BTW, thanks for the help.
Sean |
|
Back to top |
|
|
larsivi Site Admin
Joined: 27 Mar 2004 Posts: 453 Location: Trondheim, Norway
|
Posted: Tue Nov 02, 2004 1:17 am Post subject: |
|
|
sean wrote: | I thought about using "DigitalMars" but I assumed this flag would be set for both Windows and Linux right now, since both use the DM front end (?). |
I think GDC got rid of the DigitalMars version flag. |
|
Back to top |
|
|
sean
Joined: 24 Jun 2004 Posts: 609 Location: Bay Area, CA
|
Posted: Thu Nov 04, 2004 10:28 am Post subject: |
|
|
Thanks.
FYI, I put up a small fix to the headers today. math.d had a few references to "long double" and complex.d had a function called "creal," which I commented out. |
|
Back to top |
|
|
BenHinkle
Joined: 27 Mar 2004 Posts: 76
|
Posted: Fri Nov 12, 2004 3:21 pm Post subject: |
|
|
sean wrote: |
By the way, I updated the lib stuff on friday to use wchar_t aliases. If the version you've got doesn't use them you may want to re-download. |
I was just browsing this discussion and noticed the talk about wchar_t. I recently discussed with Walter a "fix" to the wprintf declared in object.d The fix is to declare an alias wchar_t that on Win32 is wchar and on Linux is dchar and use that in wprintf instead of a plain ol' wchar. I don't know what Walter will do with that change or if it will conflict with your wchar_t but I thought I'd give you a head's up. |
|
Back to top |
|
|
sean
Joined: 24 Jun 2004 Posts: 609 Location: Bay Area, CA
|
Posted: Fri Nov 12, 2004 3:36 pm Post subject: |
|
|
That's pretty much what I've already done in my C headers. It may mean a bit more work to integrate them with Phobos, but I'll deal with that when it happens--I've considered offering my C headers to Walter, perhaps that would make life easier for all of us |
|
Back to top |
|
|
|