Technically, you can (see code below), but you shouldn't. Also, whether on the stack or heap, you only have a pointer to the object, not the object itself. That is, you should write Fraction *c , not Fraction c .
// Allocate an Objective-C object on the stack. // Original code By Graham Lee: // https://gist.github.com/iamleeg/5290797 #import <Foundation/Foundation.h>
alloca() is non-standard, unsafe, non portable, and prone to stack overflows.
source share