/******************************************************************************
Welcome to GDB Online.
GDB online is an online compiler and debugger tool for C, C++, Python, Java, PHP, Ruby, Perl,
C#, OCaml, VB, Swift, Pascal, Fortran, Haskell, Objective-C, Assembly, HTML, CSS, JS, SQLite, Prolog.
Code, Compile, Run and Debug online from anywhere in world.
*******************************************************************************/
#include <stdio.h>
/*---------------------------------------------------------------------------*/
// Typedef
/*---------------------------------------------------------------------------*/
typedef struct
{
int x,y,w,h;
} BoxStruct;
/*---------------------------------------------------------------------------*/
// Globals
/*---------------------------------------------------------------------------*/
// Declare an array of boxes, the old fashioned way.
BoxStruct foo[] = // Initialize four boxes
{
{ 0, 0, 100, 10},
{ 10, 10, 90, 10 },
{ 20, 20, 80, 10 },
{ 30, 30, 70, 10 }
};
// Declare an array of boxes, the new fangled way.
#define BOX1 0
#define BOX2 1
#define BOX3 2
#define BOX4 3
#define BOX_MAX 4
// Initialize by element number, in order.
BoxStruct foo2[BOX_MAX] =
{
[BOX1] = { 0, 0, 100, 10},
[BOX2] = { 10, 10, 90, 10 },
[BOX3] = { 20, 20, 80, 10 },
[BOX4] = { 30, 30, 70, 10 }
};
// Initialize by element number, out of order.
BoxStruct foo3[BOX_MAX] =
{
[BOX3] = { 20, 20, 80, 10 },
[BOX1] = { 0, 0, 100, 10},
[BOX4] = { 30, 30, 70, 10 },
[BOX2] = { 10, 10, 90, 10 }
};
/*---------------------------------------------------------------------------*/
// Prototypes
/*---------------------------------------------------------------------------*/
void ShowBox (BoxStruct box);
/*---------------------------------------------------------------------------*/
// Functions
/*---------------------------------------------------------------------------*/
void ShowBox (BoxStruct box)
{
printf ("x:%d y:%d w:%d h%d\r\n", box.x, box.y, box.w, box.h);
}
int main()
{
printf ("---foo---\r\n");
for (int idx=0; idx<4; idx++)
{
ShowBox (foo[idx]);
}
printf ("---foo2---\r\n");
for (int idx=0; idx<4; idx++)
{
ShowBox (foo2[idx]);
}
printf ("---foo3---\r\n");
for (int idx=0; idx<4; idx++)
{
ShowBox (foo3[idx]);
}
return 0;
}
/*---------------------------------------------------------------------------*/
// End of main.c