Share
Embed
Transcript
48 slides
-
Daily used C/Obj-C const int * const ptr; const int
* (* const * ptr)(float); int fun(char * restrict src, char * restrict src); UIColor* __autoreleasing red = ...; void (^block)(int volatile *, int volatile *); -
Daily used C/Obj-C const int * const ptr; const int
* (* const * ptr)(float); int fun(char * restrict src, char * restrict src); UIColor* __autoreleasing red = ...; Understand standard C89 declarations void (^block)(int volatile *, int volatile *); -
Daily used C/Obj-C const int * const ptr; const int
* (* const * ptr)(float); int fun(char * restrict src, char * restrict src); UIColor* __autoreleasing red = ...; C99 optimization keywords void (^block)(int volatile *, int volatile *); -
Daily used C/Obj-C const int * const ptr; const int
* (* const * ptr)(float); int fun(char * restrict src, char * restrict src); void (^block)(int volatile *, int volatile *); UIColor* __autoreleasing red = ...; Lockless operations -
Daily used C/Obj-C const int * const ptr; const int
* (* const * ptr)(float); int fun(char * restrict src, char * restrict src); UIColor* __autoreleasing red = ...; Objective-C ARC keywords void (^block)(int volatile *, int volatile *); -
int const * intPtr; Declare variable intPtr as a pointer
to const int const int a = 4; int const * intPtr = &a; int b = 5; intPtr = &b; //compile error -
int * const a; // const pointer to int int
const * const a; // const pointer to const int int const * a; // pointer to const int const int * a; // pointer to const int If no type/pointer on left, the qualifier applies to type next to it right -
int const arr[3]; arr [3] const int Declare arr as
array 3 of const int int * const func(float); func (float) const * int Declare func as function(float) returning const pointer to int -
int const arr[3]; arr [3] const int Declare arr as
array 3 of const int int * const func(float); func (float) const * int Declare func as function(float) returning const pointer to int -
int const arr[3]; arr [3] const int Declare arr as
array 3 of const int int * const func(float); func (float) const * int Declare func as function(float) returning const pointer to int -
int const arr[3]; arr [3] const int Declare arr as
array 3 of const int int * const func(float); func (float) const * int Declare func as function(float) returning const pointer to int -
int const arr[3]; arr [3] const int Declare arr as
array 3 of const int int * const func(float); func (float) const * int Declare func as function(float) returning const pointer to int -
int const arr[3]; arr [3] const int Declare arr as
array 3 of const int int * const func(float); func (float) const * int Declare func as function(float) returning const pointer to int -
int const arr[3]; arr [3] const int Declare arr as
array 3 of const int int * const func(float); func (float) const * int Declare func as function(float) returning const pointer to int -
int (*const arr)[3]; arr const * [3] int Declare arr
as const pointer to array 3 of int int (* const * func[2])(float); func [2] * const * (float) int func is array 2 of pointer to const pointer to function(float) returning int -
int (*const arr)[3]; arr const * [3] int Declare arr
as const pointer to array 3 of int int (* const * func[2])(float); func [2] * const * (float) int func is array 2 of pointer to const pointer to function(float) returning int -
int (*const arr)[3]; arr const * [3] int Declare arr
as const pointer to array 3 of int int (* const * func[2])(float); func [2] * const * (float) int func is array 2 of pointer to const pointer to function(float) returning int -
int (*const arr)[3]; arr const * [3] int Declare arr
as const pointer to array 3 of int int (* const * func[2])(float); func [2] * const * (float) int func is array 2 of pointer to const pointer to function(float) returning int -
int (*const arr)[3]; arr const * [3] int Declare arr
as const pointer to array 3 of int int (* const * func[2])(float); func [2] * const * (float) int func is array 2 of pointer to const pointer to function(float) returning int -
int (*const arr)[3]; arr const * [3] int Declare arr
as const pointer to array 3 of int int (* const * func[2])(float); func [2] * const * (float) int func is array 2 of pointer to const pointer to function(float) returning int -
int (*const arr)[3]; arr const * [3] int Declare arr
as const pointer to array 3 of int int (* const * func[2])(float); func [2] * const * (float) int func is array 2 of pointer to const pointer to function(float) returning int -
int (*const arr)[3]; arr const * [3] int Declare arr
as const pointer to array 3 of int int (* const * func[2])(float); func [2] * const * (float) int func is array 2 of pointer to const pointer to function(float) returning int -
int (*const arr)[3]; arr const * [3] int Declare arr
as const pointer to array 3 of int int (* const * func[2])(float); func [2] * const * (float) int func is array 2 of pointer to const pointer to function(float) returning int -
int (*const arr)[3]; arr const * [3] int Declare arr
as const pointer to array 3 of int int (* const * func[2])(float); func [2] * const * (float) int func is array 2 of pointer to const pointer to function(float) returning int -
int (^(^ adder)(int))(int) adder ^(int) ^(int) int adder is a
block(int) returning block(int) returning int Now you can read any kind of type declarations!! -
• const (C89) • volatile (C89) • restrict (C99) •
__weak • __strong • __autoreleasing • __unsafe_unretained -
• static (C89) • auto (default, C89) • extern (C89)
• register (not a type qualifier, C89) • __block (Clang extension) • typedef (act like storage specifier) -
static const int a; storage specifier type qualifier typedef const
int MyInt typedef static int MyInt -
Objective-C ARC qualifiers • Used for explicit ARC declaration •
Apply on objective-c pointers -
__weak FCController * w_self = self; FCController __weak * w_self
= self; FCController * __weak w_self = self; -
FCController * __weak w_self = self; self.block = ^{ FCController
* __strong s_self = w_self; if (s_self != nil) { // self retained s_self.point = CGMakePoint(....); // blah } }; Use weak self to break retain cycle -
CGColorRef redRef; @autorelease{ UIColor* __autoreleasing red = [UIColor redColor]; redRef
= CFRetain([red CGColor]); // redRef retain count: 2 } // redRef retain count: 1 CALayer *layer = [CALayer layer]; [layer setBackgroundColor redRef]; CFRelease(redRef); // redRef retain count: 0, freed Explicitly call autorelease -
void function (void* data) { int [] array; array =
(int []) data; // fail } int [] is implicit int * const void function (void* data) { int * array; array = (int *) data; }