Warning: Creating default object from empty value in /home/patricknevindwyer/digilutionary.com/wp-includes/functions.php on line 292
Patrick Dwyer

Echo :: Objective-C

in News, Comparative Programming, Objective-C by patrick

Deprecated: preg_replace(): The /e modifier is deprecated, use preg_replace_callback instead in /home/patricknevindwyer/digilutionary.com/wp-includes/functions-formatting.php on line 76

This program is part of the Comparative Programming :: Echo set of examples.

The code for our Objective-C example should look startlingly familiar; almost an exact copy of the C version. The only major difference is the use of an “import” statement instead of an “include”. This is because Objective-C is a superset of ANSI-C, therefor any valid C program is also a valid Objective-C program. The examples will start to differ significanly as we take advantage of Objective-C’s object oriented characteristics, but for our echo program we can stick with a near C example.

#import <stdio.h>

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

int i;
for (i = 1; i < argc; i++) {
printf("%s ", argv[i]);

Program Source: echo.m

Compiling the example

From the command line:

gcc echo.m -o echo_objc

Running the example

From the command line:

./echo_objc Hello World