-
Notifications
You must be signed in to change notification settings - Fork 2
Objective C
Gregory Morrison edited this page Feb 5, 2023
·
3 revisions
Objective-C is a superset of C introduced by Apple in 1983. On my first try with this language, I took my Euler1.C program and tried compiling it with the GNU Objective-C compiler, gcc-objc. Presto - it worked!
// Euler1 in Objective-C
#import <stdio.h>
int euler(int n) {
int retval = 0;
for (int i=0; i<n; i++) {
if ((i % 3 == 0) || (i % 5 == 0)) {
retval += i;
}
}
return retval;
}
main() {
printf("%i\n", euler(1000));
}
So what did we learn? Well, not much besides how to compile Objective C code. I still have not a clue what distinguishes this language. This language is yet another on my to-learn list.
To install Objective-C in Fedora, install gcc-objc, gnustep-base-devel, and other assorted dependencies. Then compile and execute as follows. Warning - my gcc-objc did compile my code, but not without setting some arcane compatibility mode option:
$ gcc -std=c99 euler1.m -o euler1
$ ./euler1
233168
Return home