Unsurprisingly, the relaxed rules about C pointer types have resulted in people using them where other, more restricted types, would be preferred. Perhaps it's time for the language to get more involved in policing this.
Do you have a link to examples of people using it as such?
How this will work:
thisfileisautotranslatedfromc. Nobody wants to type that![*c] pointers. Otherwise, the compile error is error: [*c] pointers are only allowed in auto-translated C code, note: * and [*] pointers may be used where a [*c] pointer is expected. Another use case for using C pointers is for testing, i.e.
https://github.com/ziglang/zig/pull/3111/files#diff-9bb6309b18efdcc04260fad6ad9f55edR83
So would we add the thisfileisautotranslatedfromc token to this test file...even though it isn't translated from C?
https://github.com/ziglang/zig/pull/3111/files#diff-9bb6309b18efdcc04260fad6ad9f55edR91
I could be missing something, but there seems to be more valid use cases for C pointers besides translating from C. If you're interfacing with a C library, maybe you need to write some utility functions that help bridge the GAP between Zig and C? It may make sense to use C pointers to add special handling for those specific pointer types?
One thought came to mind. You could also always allow C pointers in test blocks. That would solve the problem of using C pointers in test code. But still not sure whether or not there are other valid use cases for C pointers...
I had a thought today re: C pointers: all [*c]T are currently nullable. What if we instead translated C pointers as ?[*c]T, which would be a "optional C pointer". (you could get a plain [*c]T if the C source had __attribute__((nonnull)))
That was [*c] only means "unknown if single pointer or pointer to many"?
<riba> i need to provide a callback to C code that takes a ** argument
<riba> i tried it like this: [*c][*c]
<riba> now i want to check both pointers to null
<riba> and "if (stanza == null || stanza.* == null)" does not work
perhaps, we could add a note suggesting to use a different pointer type, rather than adding a new keyword. e.g. note: * and [*] pointers may be used where a [*c] pointer is expected.
Random thought: rename [*c]T to [*ambiguous]T or even [*autotranslated]T
@hryx [*ambiguous]T seems descriptive plus awful to type which probably is good for C pointers :+1:
Most helpful comment
How this will work:
thisfileisautotranslatedfromc. Nobody wants to type that![*c]pointers. Otherwise, the compile error iserror: [*c] pointers are only allowed in auto-translated C code,note: * and [*] pointers may be used where a [*c] pointer is expected.