Who will call the main method in the lens c

I want to know who will call the main method in objective-c?

I know that the UIApplicationMain method (nil, nil, nil, NSStringFromClass [Appdelgate class]) calls the main () method, and then the process continues from the appdelegate didFinishLaunchingWithOptions () method .....

And I also know that the main () method in java is called by the JVM, and the process comes from the main () method.

I want to know who will call main () in objective-c.

thanks for the help

+5
source share
4 answers

An easy way to find out is to stick to a breakpoint at main()and take a look:

call stack

, , main() start. start, , . , :

0x1c30:  pushl  $0
0x1c32:  movl   %esp, %ebp
0x1c34:  andl   $-16, %esp
0x1c37:  subl   $16, %esp
0x1c3a:  movl   4(%ebp), %ebx
0x1c3d:  movl   %ebx, (%esp)
0x1c40:  leal   8(%ebp), %ecx
0x1c43:  movl   %ecx, 4(%esp)
0x1c47:  addl   $1, %ebx
0x1c4a:  shll   $2, %ebx
0x1c4d:  addl   %ecx, %ebx
0x1c4f:  movl   %ebx, 8(%esp)
0x1c53:  movl   (%ebx), %eax
0x1c55:  addl   $4, %ebx
0x1c58:  testl  %eax, %eax
0x1c5a:  jne    0x00001c53               ; start + 35
0x1c5c:  movl   %ebx, 12(%esp)
0x1c60:  calll  0x00001c70               ; main at main.m:9
0x1c65:  movl   %eax, (%esp)
0x1c68:  calll  0x00002376               ; exit
0x1c6d:  hlt    
0x1c6e:  nop    
0x1c6f:  nop   

MacOS X main(), , main() start . Mac start , . , start start - , .

+3

, . . , , .

. , , . , main().

+2

Objective-C C, ( C\++ Objective-C)). , , . Objective-C gcc Clang.

, , ? C Assembly\ ( Assembly - ). , Java; . main() C - , "", . main() "jmp".

, , Xcode ? -, gcc/Clang Assembly\machine. -, Xcode . -, (OS X iOS ) , .

, main() . Java, , "" JVM.

, , main() .

+1

All Articles