Objective-C is a programming language created in 1984 by Brad Cox.
#44on PLDB | 39Years Old | 536kRepos |
Try now: Riju
Objective-C is a general-purpose, object-oriented programming language that adds Smalltalk-style messaging to the C programming language. It was the main programming language used by Apple for the OS X and iOS operating systems, and their respective application programming interfaces (APIs) Cocoa and Cocoa Touch prior to the introduction of Swift. The programming language Objective-C was originally developed in the early 1980s. Read more on Wikipedia...
#import <Foundation/Foundation.h>
int main() {
NSAutoreleasePool *pool = [[NSAutoreleasePool alloc] init];
NSLog(@"Hello, world!");
[pool drain];
return 0;
}
/*
Build on OS X:
clang -framework Foundation -fobjc-arc objc.m -o objc
Build on Linux with GNUstep:
clang `gnustep-config --objc-flags` `gnustep-config --base-libs` -fobjc-nonfragile-abi -fobjc-arc objc.m -o objc
*/
#import <Foundation/Foundation.h>
int main(void)
{
NSLog(@"Hello World");
}
/* Hello World in Objective-C.
** Since the standard implementation is identical to K&R C,
** a version that says hello to a set of people passed on
** the command line is shown here.
*/
#include <stdio.h>
#include <objpak.h>
int main(int argc,char **argv)
{
id set = [Set new];
argv++;while (--argc) [set add:[String str:*argv++]];
[set do:{ :each | printf("hello, %s!\n",[each str]); }];
return 0;
}
#import "Foo.h"
@implementation Foo
@end
-(void) firstLabel: (int)param1 secondLabel: (int)param2;
auto break case char const continue default do double else enum extern float for goto if inline int long register restrict return short signed sizeof static struct switch typedef union unsigned void volatile while _Bool _Complex _Imaginary BOOL Class bycopy byref id IMP in inout nil NO NULL oneway out Protocol SEL self Super YES @ @interface @end @implementation @protocol @class @public @protected @private @property @try @throw @catch() @finally @synthesize @dynamic @selector atomic nonatomic retain
Feature | Supported | Token | Example |
---|---|---|---|
Conditionals | โ | ||
Switch Statements | โ | ||
Constants | โ | ||
While Loops | โ | ||
MultiLine Comments | โ | /* */ | /* A comment */ |
Print() Debugging | โ | printf | |
Comments | โ | // A comment |
|
Message Passing | โ | ||
Line Comments | โ | // | // A comment |
Interfaces | โ | @protocol Printing -(void) print; @end |
|
File Imports | โ | // #import ensures that a file is only ever included once so that you never have a problem with recursive includes. #import |
|
Constructors | โ | ||
Pointers | โ | ||
Single Dispatch | โ | ||
Strings | โ | " | "hello world" |
Scientific Notation | โ | ||
Case Sensitivity | โ | ||
Assignment | โ | ||
Increment and decrement operators | โ | ||
Zero-based numbering | โ | ||
Variadic Functions | โ | double average(int count, ...) { // } |
|
Operators | โ | 1 + 1; |
|
Manual Memory Management | โ | #include |
|
Macros | โ | // https://learn.microsoft.com/en-us/cpp/preprocessor/macros-c-cpp?redirectedfrom=MSDN&view=msvc-170 // https://gcc.gnu.org/onlinedocs/cpp/Macro-Arguments.html #define min(X, Y) ((X) < (Y) ? (X) : (Y)) x = min(a, b); โ x = ((a) < (b) ? (a) : (b)); y = min(1, 2); โ y = ((1) < (2) ? (1) : (2)); z = min(a + 28, *p); โ z = ((a + 28) < (*p) ? (a + 28) : (*p)); |
|
Integers | โ | int pldb = 80766866; |
|
Type Casting | โ | double da = 3.3; double db = 3.3; double dc = 3.4; int result = (int)da + (int)db + (int)dc; //result == 9 |
|
Directives | โ | #include |
|
Gotos | โ | // C/C++ program to check if a number is // even or not using goto statement #include |
|
Structs | โ | struct account { int account_number; char *first_name; char *last_name; float balance; }; |
|
Symbol Tables | โ | // Declare an external function extern double bar(double x); // Define a public function double foo(int count) { double sum = 0.0; // Sum all the values bar(1) to bar(count) for (int i = 1; i <= count; i++) sum += bar((double) i); return sum; } // Symbol Table: // Symbol name|Type|Scope // bar|function, double|extern // x|double|function parameter // foo|function, double|global // count|int|function parameter // sum|double|block local // i|int|for-loop statement |
|
Bitwise Operators | โ | int i = 4; /* bit pattern equivalent is binary 100 */ int j = i << 2; /* makes it binary 10000, which multiplies the original number by 4 i.e. 16 */ |
|
Assert Statements | โ | #include |
|
Ternary operators | โ | #include |
|
Characters | โ | char character = 'P'; |
|
Booleans | โ | ||
Enums | โ | enum Gender { Male, Female, }; |
|
Case Insensitive Identifiers | X | ||
Semantic Indentation | X | ||
Operator Overloading | X | ||
Garbage Collection | X | ||
Fixed Point Numbers | X | ||
Exceptions | X | ||
Classes | X | ||
Access Modifiers | X | ||
Templates | X | ||
Multiple Inheritance | X | ||
Namespaces | X | ||
Regular Expression Syntax Sugar | X | ||
Variable Substitution Syntax | X |