# Printf behaviour with two unsigned longs..

**URL:** <https://forums.digi.com/t/printf-behaviour-with-two-unsigned-longs/10619>\
**Category:** Rabbit\
**Created:** [June 11, 2011, 5:50pm UTC](https://forums.digi.com/t/printf-behaviour-with-two-unsigned-longs/10619 "2011-06-11T17:50:43Z")\
**Posts on this page:** 3\
**Page:** 1

<div class="post-metadata">

**Author:** ![dave373](https://avatars.discourse-cdn.com/v4/letter/d/a6a055/32.png) [@dave373](https://forums.digi.com/u/dave373)\
**Post date:** [June 11, 2011, 5:50pm UTC](https://forums.digi.com/t/printf-behaviour-with-two-unsigned-longs/10619/1 "2011-06-11T17:50:43Z")

</div>

Could someone please try this and post the result… for my sanity…

```auto

#class auto
#memmap xmem
void main(void)
{
	long start_time;
	long diff;

	start_time=SEC_TIMER;

	while (1)
	{
  		costate
  		{
  			waitfor(DelaySec(1));
  		   diff	= (long)(SEC_TIMER-start_time);
			printf("SEC_TIMER=%u start_time=%u
",SEC_TIMER, start_time);
			printf("start_time=%u
", start_time);
			printf("diff=%ld inline=%ld

", diff, (long)(SEC_TIMER-start_time));
		}
	}
}

```

I get this output…

SEC\_TIMER=21321 start\_time=18  
start\_time=21320  
diff=1 inline=1

SEC\_TIMER=21322 start\_time=18  
start\_time=21320  
diff=2 inline=2

SEC\_TIMER=21323 start\_time=18  
start\_time=21320  
diff=3 inline=3

SEC\_TIMER=21324 start\_time=18  
start\_time=21320  
diff=4 inline=4

SO…

On the first printf line, the start\_time is not working, but it is fine on the second printf on its own… WTF??? Is this a possible compiler problem??

I am using DC10.66 with a RCM5400W if it makes any difference…

Dave

---

<div class="post-metadata">

**Author:** ![petermcs](https://avatars.discourse-cdn.com/v4/letter/p/4af34b/32.png) [@petermcs](https://forums.digi.com/u/petermcs)\
**Post date:** [June 12, 2011, 10:35am UTC](https://forums.digi.com/t/printf-behaviour-with-two-unsigned-longs/10619/2 "2011-06-12T10:35:25Z")

</div>

Hi Dave,

You should be using %lu for the printfs, %u is unsigned 16bit value, %lu is unsigned 32 bit value. The program was printing the low order word of SEC\_TIMER and then the high order word of SEC\_TIMER in the first printf. It never got to start time at all.

Regards,  
Peter

---

<div class="post-metadata">

**Author:** ![cpigilam](https://avatars.discourse-cdn.com/v4/letter/c/fbc32d/32.png) [@cpigilam](https://forums.digi.com/u/cpigilam)\
**Post date:** [August 5, 2011, 6:32am UTC](https://forums.digi.com/t/printf-behaviour-with-two-unsigned-longs/10619/3 "2011-08-05T06:32:32Z")

</div>

Hello,  
I got this output

SEC\_TIMER=200 start\_time=0  
start\_time=130  
diff=70 inline=70

SEC\_TIMER=201 start\_time=0  
start\_time=130  
diff=71 inline=71

SEC\_TIMER=202 start\_time=0  
start\_time=130  
diff=72 inline=72

SEC\_TIMER=203 start\_time=0  
start\_time=130  
diff=73 inline=73

SEC\_TIMER=204 start\_time=0  
start\_time=130  
diff=74 inline=74

I am using the 10.64
