d2jsp
Log InRegister
d2jsp Forums > Off-Topic > Computers & IT > Programming & Development > Question About Long Variable
Add Reply New Topic New Poll
Member
Posts: 31,338
Joined: Mar 25 2009
Gold: 0.00
Apr 22 2017 09:47pm
I read you have to put 'L' at the end of a Long variable

So i was wondering what to do when the value of long variable is an expression?

long myLong = (myByte * 10) + 50_000 + (myShort + myInt);


^I try to put 'L' at the end and it gives me an error
Member
Posts: 31,338
Joined: Mar 25 2009
Gold: 0.00
Apr 22 2017 11:28pm
Nvm, i guess 'L' Is only needed for Static/numeric values
Member
Posts: 32,925
Joined: Jul 23 2006
Gold: 3,804.50
Apr 22 2017 11:29pm
Quote (ferf @ Apr 22 2017 11:47pm)
I read you have to put 'L' at the end of a Long variable


Incorrect. you put L at the end of literals, not variables.
Member
Posts: 31,338
Joined: Mar 25 2009
Gold: 0.00
Apr 23 2017 12:24am
Quote (carteblanche @ Apr 23 2017 01:29am)
Incorrect. you put L at the end of literals, not variables.


that's what i meant :|
Member
Posts: 966
Joined: Apr 21 2017
Gold: 2,006.96
Apr 23 2017 11:39am
Quote (ferf @ Apr 22 2017 11:24pm)
that's what i meant :|


Typically you only put L at the end of a pure literal

long foo = 20.0L;

For your case, you might need to do -

long myLong = (myByte * 10L) + 50_000L + (myShort + myInt);

Tho, I would imagine even without those the compiler would do the right thing.
Member
Posts: 14,631
Joined: Sep 14 2006
Gold: 575.56
Apr 23 2017 04:03pm
Quote (MemoryOfLight @ Apr 23 2017 11:39am)
Typically you only put L at the end of a pure literal

long foo = 20.0L;

For your case, you might need to do -

long myLong = (myByte * 10L) + 50_000L+ (myShort + myInt);

Tho, I would imagine even without those the compiler would do the right thing.


except you cant put 20.0 in a long since it's not a floating type but ya
Member
Posts: 966
Joined: Apr 21 2017
Gold: 2,006.96
Apr 24 2017 02:55pm
Quote (Ideophobe @ Apr 23 2017 03:03pm)
except you cant put 20.0 in a long since it's not a floating type but ya


Ah yea, typo my bad :D

So used to doing it with f lol

This post was edited by MemoryOfLight on Apr 24 2017 02:55pm
Go Back To Programming & Development Topic List
Add Reply New Topic New Poll