Skip to content

Instantly share code, notes, and snippets.

@pppoe
Created August 25, 2011 02:46
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save pppoe/1169856 to your computer and use it in GitHub Desktop.
Save pppoe/1169856 to your computer and use it in GitHub Desktop.
An unfamiliar way to initialize structure array
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