unsigned long arithmetics problem

Hey folks

i am having a big headache adding number to unsigned long

my code is

static time_t addTime(Time fir, Time oth) {
      unsigned int total = (oth.hours * 3600) + (oth.minutes * 60) + oth.seconds;
      time_t temp = total + fir.stamp;
      return temp;

please help me out

i wanna add total (43200 ) to fir.stamp ( which is of type time_t from timeLib.h ( 948209158 ) ) the answer should be = 948252358 but i get the answer = 948186822

from time library

if !defined(__time_t_defined) // avoid conflict with newlib or other posix libc

typedef unsigned long time_t;


thanks in advance :)

unsigned int total is that part of the problem?

948252358 - 948186822 = 65536 :o

First of all, tell us which time library. There are a few.

Since the function returns a 'time_t', then why not use a 'time_t' ?

time_t temp = (time_t) oth.seconds;
temp += (time_t) oth.minutes * 60UL;
temp += (time_t) oth.hours * 3600UL;
temp += (time_t) fir.stamp;
return temp;

I doubt if you need that code. You want to add the number of seconds since that day to a 'stamp' ? What if the result happens to be in the next day ?

Thanks @koepel it worked flawlessly :D