Archive for April 13, 2023

Thursday, April 13, 2023

C23 Standard Sets the World on Fire

Terence Kelly and Borer Yekai Pan (via Hacker News):

Like the previous major revision, C11, the latest standard introduces several useful features. The most important, if not the most exciting, make it easier to write safe, correct, and secure code. For example, the new <stdckdint.h> header standardizes checked integer arithmetic[…]

[…]

In addition to these new correctness and safety aids, C23 provides many new conveniences: Constants true, false, and nullptr are now language keywords; mercifully, they mean what you expect. The new typeof feature makes it easier to harmonize variable declarations. The preprocessor can now #embed arbitrary binary data in source files. Zero-initializing stack-allocated structures and variable-length arrays is a snap with the new standard ={} syntax.

[…]

Standard C hides behind a paywall: The official standard currently costs more than $200, so most coders make do with unofficial drafts. The standard routinely confuses its own authors, and crucial parts mystify even experienced and well-educated programmers; baffled silence is not consent.

[…]

C23 furthermore gives the compiler license to use an unreachable annotation on one code path to justify removing, without notice or warning, an entirely different code path that is not marked unreachable[…]

[…]

Imagine, then, my dismay when I learned that C23 declares realloc(ptr,0) to be undefined behavior, thereby pulling the rug out from under a widespread and exemplary pattern deliberately condoned by C89 through C11.

Previously:

Casting in XCTest Methods

Paul Samuels:

The XCTest framework added the super helpful function XCTUnwrap back in Xcode 11. At the time I added a similar helper to my various projects to help smooth over the many cases where casting is required. The idea is to have a similar call site to XCTUnwrap but for use in situations where you want to verify you have the right type or fail.

His example also demonstrates using the new record(_ issue: XCTIssue) method, which lets you provide more information than just failing with a string description.

I added casting to my tests around the time I added unwrapping and find it very helpful. And you can often use type inference to avoid having to pass in the type.

Previously:

Checking the Real Apple Account Balance

John Gordon:

His account [in the Mac App Store] shows $150 as a balance, but that’s wrong. If you click on Profile and drill down to this Accounts page (requires authentication) you will see the correct amount of $135.37. Evidently the amount displayed on the App Store screen is copied there from another system and there’s a time lag. In my testing I’ve found that the lag is at least a day and I suspect it only updates when one checks the Apple Account (requires authentication). So, in reality, the Apple Account is the only way to know this number.

Apple doesn’t mention this, but you can also get to this Accounts page (which has the accurate numbers) from iTunes/Music. You can’t get to it from the web however; appleid.apple.com doesn’t have this data.

I’ve also found the displayed balance to often be stale and inconsistent among different devices and apps.

macOS Cursor Images

Matt Birchler (Hacker News):

Some design assets some of you may love!

macOS Cursors has SVGs of basically (actually?) every cursor from macOS.

Emoji Toolkit has 135 common emoji in vector format (Figma, Sketch, and Photoshop versions) so you ever need to use emoji at larger sizes than like 72pts.

ishvanl:

Final Cut Pro, Apple’s flagship video editing software, overrides the default MacOS cursor with a nearly identical, but slightly different cursor shape. It’s almost exactly the same as the standard retina MacOS cursor but the little “stem” at the bottom is shorter & points slightly more to the right. I’d expect this from a weird niche bit of open source software, but for one of the Mac’s flagship applications it’s a bit strange. Perhaps someone here could enlighten me to the purpose of this bizarre quirk.

ChilledTonic:

If you want to investigate the history of the macOS cursor, and other cursor schemes, I highly recommend this video.

Previously:

Update (2023-04-22): Léo Natan:

It seems that SwiftUI caches the current cursor image, so even if it is changed in Settings, Settings itself displays the wrong cursor on screens that have been rendered at least once.