Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Difference between type and lifetime qualifiers

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?

like image 948
Espresso Avatar asked Mar 22 '26 14:03

Espresso


1 Answers

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) and restrict (no alias).

Automatic reference counting (for Objective-C) adds four new type qualifiers: __autoreleasing, __strong, __unsafe_unretained and __weak. Because of the nature of ARC — namely, automating memory management — these four type qualifiers attach attributes related to ownership.

I guess what I'm really asking is, is the __weak and const the same in terms of classification?

They’re both type qualifiers but only __weak is an ownership qualifier.

Can I interchange the terms type and lifetime qualifiers when I'm talking about __weak, const, etc?

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.