C functions that take pointers get treated differently than Swift functions that take pointers.
C ones get treated as inout requests accross the board, where ones from Swift do not. That means Swift functions that take UnsafePointers can take let arrays (but not single values?) but C functions that take UnsafePointers get put in an inout penalty box and get upscaled to needing to be UnsafeMutatingPointers (var) as far as the Swift is concerned.
I'd rather the C and Swift individual lets get treated like the Swift Arrays do, but at the very least I'd like to understand the inconsistencies.
I straightened your test and didn't find any inconsistencies between swift & C. Below tries all possible permutations (32 = Value|Array * let|var * const|mutable * swift|C * with & | without &) the lines that caused compilation errors are commented out, and as you can see there are no cases when C compiles and swift doesn't or vice versa.
Thank you @tera for taking the time to do that. I will start a new project to recreate, because that's an interesting test.
It is, however, not the same test. Notice the Swift functions I tested were optional pointers. That is identical to the apple documentation. I had included a link to that top of the code, but I should have called it out.
I work with a lot of very old C code which have no nullability flags Adding a nullability flag anywhere means it will have to be everywhere. I'm afraid that's not a fix I can feasibly do with the code bases I work with.
I don't think it's unreasonable to think UnsafePointer<CInt>?isn't totally detached from const int*
I reran my test with nullability reintroduced (i.e. _Nullable removed from C and "?" added to swift) and got the same results, so no, it doesn't matter. Try finding when my test and your test disagree and focus on that difference to see the issue.
Note that it is possible use the NS_ASSUME_NONNULL_BEGIN / NS_ASSUME_NONNULL_END brackets to mark all pointers in a bunch of C declarations non_null if that's easier; but as per above – nullability shouldn't matter in this particular case.
I'm writing a package that has all the flags and all the functions together and then I will compare that stand alone package to my old code and what you got.
Thank you, that could end up being helpful in places where the C is under my control.
Things could become hairy when you need some of the pointers nullable and the rest non nullable (or vice versa). Whatever the default behaviour is (either nullable or non-nullable via NS_ASSUME_NONNULL_BEGIN/END brackets), if you need to opt-out of that default you'd need to mark those exceptions explicitly (_Nullable or _Nonnull respectively).
Okay everything works exactly the same for me as it did for you in the new package. Zero inconsistencies.
Bizzarely, two things that didn't work before in the old package now do:
acknowledge_cint_buffer_const(constIntArray, 3)
acknowledge_cint_buffer_const(mIntArray, 3)
I'm this close to starting a new repo with only old-style C on an entirely different computer to see if putting the flags in the old code and getting the warnings changed something in the compiler automagically. I also switch back and forth between Xcode and the package manger compiling the tests, but that shouldn't be it. Those don't cross contaminate. Right?
Maybe tomorrow. But in the mean time I must have been mistaken and I apologize for crying wolf! Thank you for all your help!