O'Reilly logo

Programming in Objective-C, Sixth Edition by Stephen G. Kochan

Stay ahead with the world's most comprehensive technology and business learning platform.

With Safari, you learn the way you learn best. Get unlimited access to videos, live online training, learning paths, books, tutorials, and more.

Start Free Trial

No credit card required

More Advanced Types of Definitions

A definition for a name can include more than a simple constant value. It can include an expression and, as you will see shortly, just about anything else!

The following defines the name TWO_PI as the product of 2.0 and 3.141592654:

#define TWO_PI  2.0 * 3.141592654

You can subsequently use this defined name anywhere in a program where the expression 2.0 * 3.141592654 would be valid. So, you could replace the return statement of the circumference method from the previous example with the following statement:

return TWO_PI * radius;

Whenever a defined name is encountered in an Objective-C program, everything that appears to the right of the defined name in the #define statement is ...

With Safari, you learn the way you learn best. Get unlimited access to videos, live online training, learning paths, books, interactive tutorials, and more.

Start Free Trial

No credit card required