Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Calculation in code

Tags:

c

math

wait

Can someone please tell me what does this line of code do?

wait = (20ul*50ul)-1ul ;    

I understand the mathematics that is carried out which is the product of 20 and 50 then subtract 1 from it but I dont understand the ul part. Is it just a unit or does it have any significance. Thank you

like image 637
sin Avatar asked Mar 07 '26 21:03

sin


2 Answers

ul is a notational shorthand for Unsigned Long.

like image 79
David W Avatar answered Mar 10 '26 12:03

David W


The ul suffix forces each constant expression to be type unsigned long.

Normally, the type of an integer constant expression is the first type in which its value can be represented. Without the suffix, each of the literal expressions 20, 50, and 1 would be type int instead of unsigned long.

For this particular calculation it doesn't really matter, but there are times when you do want to force unsigned operations on constant expressions (overflow on unsigned operations is well-defined).

like image 21
John Bode Avatar answered Mar 10 '26 12:03

John Bode