Skip to content

[Pitch] Formalize @cdecl #2813

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

Draft
wants to merge 1 commit into
base: main
Choose a base branch
from
Draft

[Pitch] Formalize @cdecl #2813

wants to merge 1 commit into from

Conversation

xymus
Copy link
Contributor

@xymus xymus commented Apr 28, 2025

Pitch to formalize @cdecl to identify global functions as callable from C code, and supporting features.

@xymus xymus marked this pull request as draft April 28, 2025 19:37

> Note: The attribute `@objc` is already accepted on enums that will be usable from `@objc` global function signatures but not from `@cdecl` functions.

Extend support for the `@implementation` attribute, introduced in [SE-0436](https://github.com/swiftlang/swift-evolution/blob/main/proposals/0436-objc-implementation.md), to global functions marked with either `@cdecl` or `@objc`. Type-checking ensures the C declaration matches the definition in Swift. Functions marks as `@implementation` are not be printed in the compatibility header.

Choose a reason for hiding this comment

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

Typo: "are not be printed"


> Note: This proposal aims to formalize, clean up and extend the long experimental `@_cdecl`. While experimental this attribute has been widely in use so we will refer to it as needed for clarity in this document.

## Motivation

Choose a reason for hiding this comment

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

This wasn't super clear to me, I think that you should lead with the fact that there are two ways Swift can support interop:

  • by having the compiler emit a header file that contains C declarations for Swift symbols
  • by implementing functions that are declared in a user-written header

and that @cdecl/@objc are for the former and @implementation for the latter.

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.

2 participants