Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Cocoa: int main function

I'm curious, what role does the int main function play in a Cocoa program? Virtually all of the sample code I've been looking at has only the following code in main.m:

#import <Cocoa/Cocoa.h>


int main(int argc, char *argv[])
{

    return NSApplicationMain(argc,  (const char **) argv);
}

What exactly is this doing, and where does the program actually start stepping through commands? It seems my conceptions need readjustment.

like image 448
Arthur Skirvin Avatar asked Jan 21 '10 16:01

Arthur Skirvin


People also ask

Is cocoa a good source of antioxidants?

Cocoa solid, cocoa butter, and chocolate are all rich sources of antioxidants. 2 Epidemiological studies show an inverse association between the consumption of cocoa and the risk of cardiovascular disease. 3, 4 The likely mechanisms are antioxidant activity; improvement in endothelial function, vascular function,...

What are the uses of cacao products?

Cocoa products are used extensively in the food and pharmaceutical industries. Cocoa powder and cocoa butter are often mixed with chocolate liquor (ground cacao seeds), sugar, milk, and other flavors.

What is the role of cocoa in pharmacology?

Uses and Pharmacology. Cocoa has been reported to be a source of natural antioxidants, 10 the free radical scavengers that preserve cell membranes, protect DNA, prevent the oxidation of low-density lipoprotein (LDL) cholesterol that leads to atherosclerosis, and prevent plaque formation in arterial walls.

What are the benefits of flavanol-containing cocoa products?

Clinical data. Numerous intervention trials have shown that consumption of flavanol-containing cocoa products can improve endothelial function 41, 43, 44, 45, 46 vascular function 44, 47, 48 and insulin sensitivity 47; as well as attenuate platelet reactivity 46, 47, 49, 50, 51, 52 and reduce blood pressure.


2 Answers

Since a Cocoa project starts like any other, the entry point for the Operating system is main. However the Cocoa Architecture is constructed to actually start the processing of your program from NSApplicationMain, which is responsible for loading the initial window from your application and starting up the Events loop used to process GUI events.

Apple has a very in depth discussion on this under the Cocoa Fundamentals Guide : The Core Application Architecture on Mac OS X

like image 183
Brandon Bodnar Avatar answered Sep 29 '22 13:09

Brandon Bodnar


If you want to learn how control passes from "launch this" to the main() function, the execve man page has the details. You would also want to read about dyld. main() is a part of the Unix standard. Every single program that you can run effectively has a main().

As others have mentioned, NSApplicationMain passes control to Cocoa. The documentation is quite specific as to what it does.

One interesting note, NSApplicationMain doesn't actually every return. That is, if you were to separate the call to NSApplicationMain from the return in your main function and put code in between, that code would never be executed.

like image 22
bbum Avatar answered Sep 29 '22 13:09

bbum