Tell me about unsafe c
Asked on 06/16/2025
2 searches
At WWDC 2025, Apple introduced several features and tools to enhance the safety of using C and C++ with Swift, particularly focusing on unsafe constructs. In the session titled "Safely mix C, C++, and Swift," they discussed how Swift, which is safe by default, can still interact with unsafe C and C++ constructs, especially when dealing with pointers.
One of the key features introduced is the Strict Memory Safety mode in Swift 6.2. This mode is not enabled by default but can be turned on to alert developers to any unsafe code, providing notes that explain the reasoning behind these alerts. This is particularly useful for applications that handle sensitive data and need to ensure security (Safely mix C, C++, and Swift).
Additionally, Swift 6.2 introduces a new safe pointer type called Span, which provides the benefits of pointers while automatically preventing common mistakes such as accessing memory out of bounds or using memory after it has been freed. This is achieved by adding annotations to C and C++ code, allowing Swift to safely call functions that use these pointers (Safely mix C, C++, and Swift).
For developers working with C and C++ code, Apple has also developed tools to enhance bound safety, such as enabling bound safety extensions in Xcode, which help identify and correct unsafe pointer usage (Safely mix C, C++, and Swift).
These efforts are part of Apple's broader initiative to make C and C++ code safer when used in conjunction with Swift, acknowledging that while it's not possible to make these languages as safe as Swift, significant improvements can be made.

Safely mix C, C++, and Swift
Learn how to mix C, C++, and Swift while improving the safety of your apps. We’ll show you how to find where unsafe C and C++ APIs are called in your Swift code, how to call them more safely, and how to make your app’s existing C and C++ code safer by default.

What’s new in Swift
Join us for an update on Swift. We’ll talk about workflow improvements that make you more productive, and new and modernized library APIs for fundamental programming tasks. We’ll show examples of Swift adoption throughout more layers of the software stack. Finally, we’ll explore new language features for both improving approachability of concurrency, and achieving peak performance when you need it.

Improve memory usage and performance with Swift
Discover ways to improve the performance and memory management of your Swift code. We’ll explore ways to refine your code – from making high-level algorithmic changes to adopting the new InlineArray and Span types for finer control over memory and allocations.