compiler bug?

14 Jun 2012

#include "mbed.h"

Serial pc(USBTX, USBRX);

int year=2012, month=6, day=12, ndays=0;
int DaysPerMonth[12];


int main() {

    pc.baud(38400);

    if (year%4 == 0 && !(year%100 == 0 && year%400 != 0)) {

        int DaysPerMonth[] = {31, 29, 31, 30, 31, 30, 31, 31, 30, 31, 30, 31};

    }   else {

        int DaysPerMonth[] = {31, 28, 31, 30, 31, 30, 31, 31, 30, 31, 30, 31};
    }

    for (int i=0; i<(month-1); i++) {
        ndays += DaysPerMonth[i];
    }
    ndays += day;


    printf("day number = %d   %d \n", ndays);

}

trying to work-up a function to calculate day number. when compiled, I always get this error "variable "DaysPerMonth" was declared but never referenced". despite the error, it will load but when run the arrays are not accessed and in this instance the answer is always 12. what gives? can anyone explain this to me (and perhaps a work around) ?? tnx very much ...

garyb

14 Jun 2012

at first glance you are declaring days per months 3 times, the int bit of the deceleration.

try something like filling the array at the first time, ie Global declaration.

as normal year. then if leep year - Feb =28

hope this is usefull

Ceri

14 Jun 2012

that does it... thanks guys