by flyx86 · 10y ago · 0 comments
If you want to use a C library „the Ada way“, you need to wrap almost every C function with an Ada function that transforms C pointers into Ada arrays (remember, [] in C is just a pointer with no dope), C defines into Ada enumerations, C function pointers to Ada subprogramm access types and so on.
This amounts to a lot of work. For example, my OpenGL Ada wrapper is roughly 10,000 lines of code. But it does do extension loading and resource management automatically (in contrast with the raw C API) and all defines have been translated to enum values so you can call functions only with values they can handle.
The operating system is in C, so to use all the operating system provides, the networking, shared memory, IPC you need a wrappers. If your sharing data with C code, you need to make sure you ada records match your C Structs so they align correctly. Ada was remarkably good at letting you set where things went in memory for each record.
Part of a past job was to write and maintain ada wrappers for a large Ada project.
This is specially visible when comparing nice C++ libraries like OWL and VCL to MFC.