Some doubts regarding the L and UL usage in arduino/embedded uC's

Ok, i cant find any decent ( actually ANY AT ALL) documentation into the usage of L and UL in Arduino.
Another question is : The DUE wont allow this as it has a different solution for it( am i right or wrong ?!)?
I would appreciate a lot if anyone has the patience to do a small concise explanation of its usage and caveats, as well as pointing me into any kind of documentation regarding it, tutorials, etc…
Im never sure when i can use it or when not to ! Meaning i rarely use it at all !! lol :slight_smile:

EXAMPLE

while (millis() - siren_start_time < 5000L);

Thanks in advance !!

another question is : The DUE wont allow this as it has a different solution for it( am i right or wrong ?!)?

You're wrong. It's a language thing, not platform. 'L' says the constant is type "long" 'UL' says it is "unsigned long"

millis() and micros() and other time related variables are all unsigned long. If you mix data types you can get weird results.

http://www.cplusplus.com/doc/tutorial/constants/

Ahhhhhh... Now it makes sense... So, by proxy, ends up working almost as same as clock cycles ( ish ?!)? At least in the example. lol At least it makes sense to me now ! Cheers for that !

iyahdub:
Ok, i cant find any decent ( actually ANY AT ALL) documentation into the usage of L and UL in Arduino.

This might help:

http://www.gammon.com.au/forum/?id=12146

while (millis() - siren_start_time < 5000L);

You don’t need “L” here. 5000 is 5000. The compiler won’t get confused.

[quote author=Nick Gammon link=topic=190752.msg1410656#msg1410656 date=1380520824]

You don't need "L" here. 5000 is 5000. The compiler won't get confused. [/quote]

I'd suggest always using L for long and UL for unsigned long constants, because then you'll not forget when it does matter (such as when you later change 5000 to 50000...)

such as when you later change 5000 to 50000

Or multiply the value by another one that causes overflow of an int.

I’d suggest always

I think always is a little strong.

for(byte i=0L, ...

sort of defeats the purpose.

But, I understand where you are coming from.

MarkT: I'd suggest always using L for long and UL for unsigned long constants, because then you'll not forget when it does matter (such as when you later change 5000 to 50000...)

Yes, however this prints 50000:

void setup ()
  {
  Serial.begin (115200);
  Serial.println ();
  Serial.println (50000); 
  }  // end of setup

void loop () { }

You may as well suggest we put in:

  Serial.begin (115200UL);

But it works without the UL.

Yes, however this prints 50000:

But this doesn't

void setup ()
{
  Serial.begin (115200);
  Serial.println (5000 * 10);
}

void loop ()
{}

;)

Absolutely. And if you cared to write:

  Serial.begin (1152 * 100);

Then it wouldn't work.

However my point is that a single number (not involved in arithmetic) does not need qualification.

Otherwise you would be writing:

unsigned long startTime = 0UL;

Otherwise you would be writing:

How does 0UL differ from 0? 8)

0 is the NULL pointer. 8^)

As opposed to 0ULL? 8^)

thanks once again !

PaulS: How does 0UL differ from 0? 8)

This is a question about zero, isn't it?

http://www.youtube.com/watch?v=BRRolKTlF6Q

I love to pick youses brains... Always learn more than i expected !! And thats why this kind of community is so strong, i think!

I think "youse" is the plural of "you" in Australian (where "you" is already plural, of course). Pluralizing it again to "youses" is something I haven't seen done before. :)

I think it's a New York City thing too, in the Brooklyn borough part of the city.

[quote author=Nick Gammon link=topic=190752.msg1418398#msg1418398 date=1381088338] I think "youse" is the plural of "you" in Australian (where "you" is already plural, of course). Pluralizing it again to "youses" is something I haven't seen done before. :) [/quote]

I don't think it's pluralizing the plural. It's possessiv-izing the plural.

You - singular. Youse - Plural. Youses - Plural possessive.