|
|
|
![]() |
|
|||||||
|
||||||||
![]() |
|
|
Thread Tools | Rate Thread | Display Modes |
|
|
|
#1
|
||||
|
||||
|
Re: A few simple programming questions;
Quote:
Technically, it's not implied. The code within the segment following the else executes no matter what if the first IF and all IF ELSEs after it fail. Another correction: == is an operator that returns a one or a zero based on whether the LHS (left hand side) is equal to the RHS. the = operator sets the LHS (which has to be a valid LHS, aka a variable) equal to the RHS. It returns the set value. C will let you get away with this: if (x = 5) stuff(); It assumes, "Oh, I know what he wants to do. He wants me to set x to five and then check to see if x or not." AKA, this will not cause a compile time error, whereas in Java it will. Note that the == returns a 1 or a 0, not any boolean value, for those used to Java or other such. The other comparisons (>, < , <=, >=, etc) work the same way. Neat but terrible shorthand (don't do this): x += x < 100; Which does? I throw it out there. Paul Dennis |
|
#2
|
|||||
|
|||||
|
Re: A few simple programming questions;
Quote:
Code:
if (x < 100)
x = x + 1;
|
|
#3
|
||||
|
||||
|
Re: A few simple programming questions;
Quote:
But there is absolutely no reason to do this. It doesn't save you any time, and it doesn't save you an space in memory. However, there is, and I kid you not, a contest to obfuscate code. This is a fairly simple example of that. Paul Dennis |
|
#4
|
|||
|
|||
|
Re: A few simple programming questions;
Quote:
Quote:
Even something as simple as always using parentheses to establish precendence instead of relying on operator precendence makes code much more understandable. |
|
#5
|
||||
|
||||
|
Re: A few simple programming questions;
Quote:
Quote:
Code:
int mod32(int x)
{
while (x > 32)
{
x -= 32;
}
return x;
}
Code:
int mod32(x)
{
return x & 31;
}
The & is a bitwise AND operation. In other words, it works with the ones and the zeroes. AND evaluates to true or one if cond1 and cond2 evaluate to one. Example: 7&11 7 = 4+2+1; 11 = 8+2+1; 0111 1011 ____ 0011 The bitwise operation works faster. It only works with powers of two (don't try x&10) but in those cases, it works. If you want, think about why (or PM me). Just draw it out. However, oftentimes the best code for processing time is the most understandable too. Also, when you think about the speed of today's processors, unless you are writing code that /needs/ to run fast, there is not much point in optimizing. [\END LECTURE] That was rather off-topic, but I found it interesting. I hope you did too (or skipped over it). Tat's all for now, folks. Tit for tat. Paul Dennis |
|
#6
|
||||
|
||||
|
Re: A few simple programming questions;
Wow, Thanks for all the help. Although that last post hurts my head. But now, I think I have everything working. We are hooking up electronics now so I haven't been able to test anything, yet. But still, I'd give you all hugs, If I could, and a cookie if I could!
Danke!!! Team 1555's only poor little programmer. |
![]() |
| Thread Tools | |
| Display Modes | Rate This Thread |
|
|
Similar Threads
|
||||
| Thread | Thread Starter | Forum | Replies | Last Post |
| How To Ask Questions the Smart Way | Brandon Martus | General Forum | 8 | 27-03-2013 15:52 |
| Programming laptops | [527]phil | Programming | 24 | 22-08-2005 12:28 |
| #1 The Journey of a FIRST Graduate: Questions | Ken Leung | General Forum | 12 | 27-07-2005 18:24 |
| Suggestion for Delphi Programming Posts | Chris Hibner | CD Forum Support | 1 | 27-07-2005 10:02 |
| Can You help us??? (programming questions) | HuskieRobotics | Programming | 1 | 24-02-2004 21:19 |