In Objective-C or any other language that applies?
I guess what I’m really asking is, is the __weak and const the same in terms of classification? Can I interchange the terms type and lifetime qualifiers when I’m talking about __weak, const, etc?
In C, a type qualifier attaches a quality (an attribute, a property) to a given type. There are three type qualifiers:
const(readonly, no writes),volatile(no cache) andrestrict(no alias).Automatic reference counting (for Objective-C) adds four new type qualifiers:
__autoreleasing,__strong,__unsafe_unretainedand__weak. Because of the nature of ARC — namely, automating memory management — these four type qualifiers attach attributes related to ownership.They’re both type qualifiers but only
__weakis an ownership qualifier.No, they’re not interchangeable. All qualifiers listed above are type qualifiers but only the four qualifiers introduced by ARC are also ownership qualifiers.
Note that the LLVM project uses the denomination ownership qualifiers whereas Apple seem to be using lifetime qualifiers instead.