|
| 21 Mar 2012 06:23 AM |
For determining if it's a long int/unsigned int
int Literals1 = 76u int Literals2 = 76l int Literals3 = 76ul
or something like
unsigned Literals4 = 76 long Literals5 = 76 |
|
|
| Report Abuse |
|
|
stravant
|
  |
 |
| Joined: 22 Oct 2007 |
| Total Posts: 2893 |
|
|
| 21 Mar 2012 07:51 AM |
Not sure what you mean by "determining if".
Regardless, in the end how you write the thing won't matter (as long as it's written correctly of course), how you write it exactly. C+++ has very good optimization, so pretty much whatever obvious way of doing it (You can make something convoluted enough to fool the optimizer, but you usually have to be trying to do that for it to happen) you choose the optimizer will get it down to the same minimal code. |
|
|
| Report Abuse |
|
|
TheMyrco
|
  |
| Joined: 13 Aug 2011 |
| Total Posts: 15105 |
|
|
| 21 Mar 2012 08:27 AM |
| I recommend doing the second way tough, better to see :) |
|
|
| Report Abuse |
|
|
Bubby4j
|
  |
| Joined: 25 Dec 2008 |
| Total Posts: 1831 |
|
|
| 21 Mar 2012 08:33 AM |
@stravent What's C+++? His question was on C++. |
|
|
| Report Abuse |
|
|
|
| 21 Mar 2012 08:43 AM |
@stravant
Oh so it doesn't matter?
And I meant "if" because when you make an int you have to define if it's like a small integer, a large integer, or if it's an unsigned integer, etc. |
|
|
| Report Abuse |
|
|
myrkos
|
  |
| Joined: 06 Sep 2010 |
| Total Posts: 8072 |
|
|
| 21 Mar 2012 09:26 AM |
The only way that works is:
unsigned int x;
long x; // Usually the same as int
short x; // half int
char x;
unsigned char x;
|
|
|
| Report Abuse |
|
|
|
| 21 Mar 2012 05:58 PM |
@myrkos
No, on the C++ documentation, it's called a constant, and if you add like a U or an L to the end of the number, it will become a long or unsigned int. |
|
|
| Report Abuse |
|
|
myrkos
|
  |
| Joined: 06 Sep 2010 |
| Total Posts: 8072 |
|
|
| 21 Mar 2012 05:58 PM |
| That doesn't affect the size of the variable. |
|
|
| Report Abuse |
|
|
|
| 21 Mar 2012 05:59 PM |
http://www.cplus plus. com/doc/tutorial/constants/ |
|
|
| Report Abuse |
|
|
myrkos
|
  |
| Joined: 06 Sep 2010 |
| Total Posts: 8072 |
|
|
| 21 Mar 2012 06:00 PM |
Still doesn't affect the size or type of the variable.
What you're doing is changing the type of the constant that the variable gets assigned to, but in your examples the variable is always an int and the constant will just be converted to an int. |
|
|
| Report Abuse |
|
|
|
| 21 Mar 2012 06:05 PM |
so adding a literal is useless
wat |
|
|
| Report Abuse |
|
|
myrkos
|
  |
| Joined: 06 Sep 2010 |
| Total Posts: 8072 |
|
|
| 21 Mar 2012 06:07 PM |
| Pretty much in this case, but it is when you're adding various numbers and want, for instance, different accuracy if you're working with floating point or whatever. |
|
|
| Report Abuse |
|
|
| |
|