Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

POSIX _t Namespace Conflict #55

Open
wahern opened this issue Dec 13, 2018 · 5 comments
Open

POSIX _t Namespace Conflict #55

wahern opened this issue Dec 13, 2018 · 5 comments

Comments

@wahern
Copy link

wahern commented Dec 13, 2018

Not many people realize this, but POSIX reserves all identifiers with the suffix "_t". See http://pubs.opengroup.org/onlinepubs/9699919799/functions/V2_chap02.html

I suspect people tend to use the _t suffix precisely because it's so ubiquitous in C and POSIX identifiers, but it's ubiquitous in those standards for the reason that it's supposed to avoid conflicts with other namespaces.

@rossberg
Copy link
Member

Hm, interesting, but the way I read it is that the restrictions stated there constrain implementations of POSIX and what implementation-specific symbols they can add to POSIX header files. AFAICS they do not constrain third-party libraries with independent header files.

For the Wasm API, all C names have consciously been given a wasm_ prefix, so I expect the potential for conflict to be minimal to non-existent.

@wahern
Copy link
Author

wahern commented Dec 13, 2018

The suffix is reserved for all POSIX and C headers. (Note the [CX], which means it's extending the C standard, which means its reserving for C headers as well.) If your code never includes a header like <stdlib.h>, then you're good. I've written C source file that didn't include any C or POSIX header. But if your code includes such a header and also defines identifiers (directly or indirectly) with the _t suffix, then there's potential for namespace clash, especially if you're defining them in headers to be used by other applications.

In practice few people know this, let alone obey it. But I figured standards should probably be neighborly.

@rossberg
Copy link
Member

Sigh, modularity and name spacing are such a sad story in C.

The only unqualified type names we define are the byte_t, float32_t, and float64_t synonyms. I agree that we should probably avoid those. (It's unfortunate that they do not exist in any standard header.)

For everything else I don't know. We indeed include some C headers. However, as mentioned, all our names are sanitised with wasm_ prefixes. If POSIX makes such a sweeping land grab in the C name space that it even prevents harmless uses like that -- and generally is in conflict with large parts of dev reality -- then I don't know if third parties should feel obliged to obey to the letter. And I'm saying that as a person who usually very much prefers conforming to standards

@wahern
Copy link
Author

wahern commented Dec 13, 2018

FWIW, the use of _t in the API doesn't really add anything. For years, before I read and understood the standards, I thought _t was an idiom for scalar typedefs (integers, pointers) or more generally (in my rationalizations) POD types that could be copied by simple assignment, and that's how I always used it. IME most software that uses _t rarely uses it for aggregate objects like structs or unions. What originally clued me into the issue was how the pthreads API uses _t for aggregate objects, including ones that couldn't be copied, which seemed irregular until I learned that the whole point of _t was for namespacing, not readability.

That said, I only wanted to bring the issue to your attention. I don't care to bikeshed style. Feel free to dispose of this issue however you want ;)

@rossberg
Copy link
Member

Actually, the main benefit of the convention from my perspective is that you don't get into syntactic issues where you want to name a variable or function after a type, because C syntax does not properly separate the name spaces.

Anyway, thanks for bringing this up. I at least want to reconsider the use of unqualified type names.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants