Created
August 25, 2011 02:46
-
-
Save pppoe/1169856 to your computer and use it in GitHub Desktop.
An unfamiliar way to initialize structure array
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
typedef struct demoStruct { | |
int val; | |
float *point; | |
} DemoStruct; | |
@implementation InitStructureAppDelegate | |
@synthesize window=_window; | |
- (BOOL)application:(UIApplication *)application didFinishLaunchingWithOptions:(NSDictionary *)launchOptions | |
{ | |
float a = 1.0f; | |
float b = 2.0f; | |
float c = 3.0f; | |
DemoStruct demos[4] = { | |
{.val = 1, .point = &a}, | |
{.val = 2}, | |
{.point = &b}, | |
{.val = 3, .point = &c}, | |
}; | |
for (int i = 0; i < 4; i++) | |
{ | |
printf("%d %f\n", demos[i].val, (demos[i].point ? *(demos[i].point) : -1.0f)); | |
} | |
// Override point for customization after application launch. | |
[self.window makeKeyAndVisible]; | |
return YES; | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment