#include<stdio.h>

#define ARRAY_LEN  (3)

typedef struct _INT_ARRAY {
    int m_data[ARRAY_LEN];
} INT_ARRAY;

// set
//  0 : ok
//  1 : param error
//  2 : index error
int INT_ARRAY__Set(INT_ARRAY * p, int index, int d)
{
    if (NULL == p) {
        return 1;
    }
    if (index < 0 || ARRAY_LEN <= index) {
        return 2;
    }
    p->m_data[index] = d;
    return 0;
}

// get
//  0 : ok
//  1 : param error
//  2 : index error
int INT_ARRAY__Get(INT_ARRAY * p, int index, int *d)
{
    if (NULL == p || NULL == d) {
        return 1;
    }
    if (index < 0 || ARRAY_LEN <= index) {
        return 2;
    }
    *d = p->m_data[index];
    return 0;
}

int main()
{
    INT_ARRAY int_data;
    int i, res, d;

    for (i = 0; i < ARRAY_LEN; i++) {
        res = INT_ARRAY__Set(&int_data, i, i);
        if (res) {
            printf("error\n");
            return 1;
        }
    }
    for (i = -1; i < ARRAY_LEN + 1; i++) { // 範囲外アクセス
        printf("int_data.m_data[%2d] = ", i);
        res = INT_ARRAY__Get(&int_data, i, &d);
        if (res) {
            printf("error\n");
        } else {
            printf("%d\n", d);
        }
    }
    return 0;
}
