Skip to content

Update docs/HowSwiftImportsCAPIs.md #30747

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

Merged
merged 1 commit into from
Apr 1, 2020
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
12 changes: 6 additions & 6 deletions docs/HowSwiftImportsCAPIs.md
Original file line number Diff line number Diff line change
Expand Up @@ -315,8 +315,8 @@ void drawStringRenamed(const char *, int xPos, int yPos)
```swift
// C header imported in Swift.

func drawString(_: UnsafePointer<CChar>!, _ xPos: Int, _ yPos: Int)
func drawStringRenamed(_: UnsafePointer<CChar>!, x: Int, y: Int)
func drawString(_: UnsafePointer<CChar>!, _ xPos: CInt, _ yPos: CInt)
func drawStringRenamed(_: UnsafePointer<CChar>!, x: CInt, y: CInt)

drawString("hello", 10, 20)
drawStringRenamed("hello", x: 10, y: 20)
Expand Down Expand Up @@ -602,9 +602,9 @@ memory layout.

As discussed above, there are cases where bridging that adjusts memory layout is
not possible, for example, when importing pointers to function pointers. For
example, while C's int `(*)(char)` can be imported as `(Int8) -> Int` (requires
example, while C's `int (*)(char)` can be imported as `(CChar) -> CInt` (requires
an adjustment of memory layout), C's `int (**)(char)` can't be imported as
`UnsafePointer<(Int8) -> Int>`, because the pointee must have identical memory
`UnsafePointer<(CChar) -> CInt>`, because the pointee must have identical memory
layout in C and in Swift.

Therefore, we need a Swift type that has a memory layout identical to C function
Expand Down Expand Up @@ -800,9 +800,9 @@ union IntOrFloat {

struct IntOrFloat {
var i: CInt { get set } // Computed property.
var f: Float { get set } // Computed property.
var f: CFloat { get set } // Computed property.
init(i: CInt)
init(f: Float)
init(f: CFloat)
init()
}
```
Expand Down