[swift-evolution] [Pitch] Renaming sizeof, sizeofValue, strideof, strideofValue

Dany St-Amant dsa.mls at icloud.com
Mon Jun 6 20:26:50 CDT 2016


> Le 3 juin 2016 à 17:11, Erica Sadun via swift-evolution <swift-evolution at swift.org> a écrit :
> 
> Discussion has more or less drawn down. Are there any further significant requests / issues that need addressing? Both standalone functions (my recommended approach)  and the MemoryLayout<T> struct approach (alternative, with reasons why I think it's not as ideal) are discussed in-proposal.
> 
> Pull Request: https://github.com/apple/swift-evolution/pull/350

Is there any need to consider the following common C sizeof() usage, which is currently illegal in Swift?

#if sizeof(MyType) != sizeof(Int)
# error "Someone added too much data to MyType"
#endif

It is not that I like fancy conditional compile, but having such compile time assertion is useful; at least in my day-time low-level C world. Most of the discussion seem to have been around sizeof() being more of a runtime function than a compiler directive; which would preclude being able to do compile time assertion to validate type size.

Dany


More information about the swift-evolution mailing list