Skip to content

Safe c interop #1071

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

Open
wants to merge 3 commits into
base: main
Choose a base branch
from
Open

Safe c interop #1071

wants to merge 3 commits into from

Conversation

hnrklssn
Copy link

@hnrklssn hnrklssn commented Jun 7, 2025

This adds documentation around __counted_by, __sized_by, API notes, and using lifetime attributes in C.
This is stacked on top of #980.

@rapidsna
Copy link

rapidsna commented Jun 7, 2025

CC @egorzhdan @Xazax-hun @DougGregor

@rauhul
Copy link
Member

rauhul commented Jun 7, 2025

Have you considered putting this documentation in a docc catalog?

@hnrklssn
Copy link
Author

hnrklssn commented Jun 7, 2025

Have you considered putting this documentation in a docc catalog?

I have not! I can't speak for Gábor and Egor, but I simply kept writing in the established file. What are the benefits of a docc catalog? I haven't contributed to the website before, so I don't really know how things work

@rapidsna
Copy link

I remember the title was "Safe C++ and Swift interop" or something like that. If so we would also need to update it to include "C" as well.

@hnrklssn hnrklssn force-pushed the safe-c-interop branch 2 times, most recently from 18b8c92 to 3605d1d Compare June 20, 2025 11:35
@hnrklssn
Copy link
Author

I'm having a bit of trouble deciding how to format the comparison between C and Swift; the narrow page size makes it hard to fit side-by-side comparisons. Following the approach used elsewhere on the page looks like this:
Screenshot 2025-06-20 at 1 16 37 PM
Code blocks cannot be used in markdown tables, so these have to be inline code snippets, which prevents formatting the code in a nicer way (as well as syntax highlighting).


Screenshot 2025-06-20 at 1 16 50 PM Using HTML tables we can get tables with code blocks. This gives us syntax highlighting, but unformatted it requires a fair bit of horizontal scrolling.
Screenshot 2025-06-20 at 1 21 22 PM With some formatting the situation improves, but they still don't fit without horizontal scrolling.
Screenshot 2025-06-20 at 1 31 41 PM We could instead skip the table and just use two separate code blocks before/after each other. Following the code formatting of the previous code blocks the C code looks like this, which works I guess, but doesn't look great right after each other imo.

Copy link
Contributor

@Xazax-hun Xazax-hun left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Looks good to me, some nits inline.

@Xazax-hun
Copy link
Contributor

I don't have a strong opinion on the formatting, looks like all approaches have pros and cons :/

@rapidsna
Copy link

+1 for the 3rd option, despite horizontal scrolling.

hnrklssn added 3 commits July 3, 2025 17:35
This adds documentation around __counted_by, __sized_by, API notes, and
using lifetime attributes in C.
- replace [[clang::noescape]] syntax with __noescape (etc)
- specify YAML syntax highlighting for YAML code blocks
- consistently use "annotation" in favour of "attribute"
- insert HTML table to enable code block in cells
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

Successfully merging this pull request may close these issues.

4 participants