What is the difference between * (id *) ((char *) object + ivar_getOffset (ivar)) and object_getIvar (object, ivar)

According to Objective-C link to runtime :

ivar_getOffset Returns the offset of an instance variable.

ptrdiff_t ivar_getOffset (Ivar ivar) Discussion For example, variables of type id or other types of objects, calling object_getIvar and object_setIvar instead of using this offset to access instance variable data directly.

Declared In runtime.h

Why is this? What does object_getIvar do for object types?

EDIT: changed the question from the signature (void *) to (id *).

+3
source share
2 answers

, ivar. , object_getIvar() Apple open-source Obj-C.

object_setIvar() , . , , objc_assign_ivar().

​​ ; , API .

+2

, , object_getIvar - , id , ivar_getOffset object, .

, void * C99 ( ):

C99 §6.2.5 (1): (...) (, ), (, ) (, , , ).

C99 §6.2.5 (19): void ; , .

C99 §6.5.6 (2): , , . ( 1.)

C99 §6.5.2.1 (1): " ", , "".

, char *.

+1

Source: https://habr.com/ru/post/1761656/


All Articles