Difference between revisions of "BoostC tiny Wiki"
Russ hensel (talk | contribs) |
Russ hensel (talk | contribs) |
||
Line 38: | Line 38: | ||
As a general rule it has been observed that many programmers spend too much time on optimization and that often the compiler can do a better job than the programmer. Often readability of the code suffers for "optimizations" that do not really optimize anything. That said, it is worthwhile to optimize the algorithm. C does not know the purpose of the code, the programmer should, the compiler can only optimize the code in doing what you said, not what you want. | As a general rule it has been observed that many programmers spend too much time on optimization and that often the compiler can do a better job than the programmer. Often readability of the code suffers for "optimizations" that do not really optimize anything. That said, it is worthwhile to optimize the algorithm. C does not know the purpose of the code, the programmer should, the compiler can only optimize the code in doing what you said, not what you want. | ||
+ | |||
+ | === Questions === | ||
Questions: | Questions: | ||
Line 45: | Line 47: | ||
Is there a time penality to using local variables. | Is there a time penality to using local variables. | ||
+ | |||
+ | |||
+ | === Optimizations that Seem to Work === | ||
+ | |||
+ | Declare variables as the simplest type that will work. Keep it small, keep it unsigned unless you need it otherwise. | ||
=== Optimizations that Seem Not to Work === | === Optimizations that Seem Not to Work === | ||
− | + | == Good Pratices == | |
Opinions may differ! | Opinions may differ! | ||
Line 64: | Line 71: | ||
ix ++; | ix ++; | ||
} | } | ||
+ | |||
+ | Use full declarations: | ||
+ | |||
+ | unsigned char ix; | ||
+ | |||
+ | //not | ||
+ | |||
+ | char ix; | ||
+ | |||
+ | The reader, and perhaps may not remember the default or remeber it correctly | ||
+ | |||
+ | Use parenthsis not operation conventions: | ||
+ | |||
+ | c = a + ( b * c ) | ||
+ | |||
+ | //not | ||
+ | |||
+ | c = a + b * c | ||
+ | |||
+ | |||
+ | == Code Snips that may Be Helpful == |
Revision as of 08:34, 12 January 2009
Contents
Introduction
This is the very beginning of a Wiki for BoostC. Its organization will probably change a lot in the near future ( if we can get the free labor required ). It may move to the SourceBoost site if they want to host it. Since BoostC is proprietary it may be inappropriate for it to grow too big here unless we can find some explicit support for it. For now here it is.
Tips/Tricks/Gotchas
Watch out for set-bit!
The function set-bit() is almost right, but it should be set_bit(). This and similar errors are subtraction, and the result is error messages ( how about a sample ) that are not very helpful.
Rebuild It
Sometimes I have been able to get rid of odd errors by forcing a rebuild by erasing all but the project file and the .c and .h files. The manual suggests that Ctrl+F7 or Ctrl+build command do pretty much the same thing.
Subroutine signatures
Often we have several versions of a subroutine with different signatures ( set and type of call arguments ) Try to check that you are calling the version you want. Casting may help.
Standard C Issues
Use a Lint Program
Has anyone configured one for BoostC?
Read This
C Traps and Pitfalls From Wikipedia, the free encyclopedia Note that there is a free download or a longer ( for purchase ) book.
Links
Optimization
As a general rule it has been observed that many programmers spend too much time on optimization and that often the compiler can do a better job than the programmer. Often readability of the code suffers for "optimizations" that do not really optimize anything. That said, it is worthwhile to optimize the algorithm. C does not know the purpose of the code, the programmer should, the compiler can only optimize the code in doing what you said, not what you want.
Questions
Questions:
Is shifting better than multiplying/dividing by poweres of 2?
does if( intcon & (1<<T0IF) ) work better than test_bit( intcon, T0IF )?
Is there a time penality to using local variables.
Optimizations that Seem to Work
Declare variables as the simplest type that will work. Keep it small, keep it unsigned unless you need it otherwise.
Optimizations that Seem Not to Work
Good Pratices
Opinions may differ!
Put a good header in the program
I keep refining my, see one of my projects like PIC Stepper Motor Demonstration and Test Project
Avoid Shortcuts
For example I always use braces with an if statement, there is less chance of error if someone adds a line:
if ( isTrue ) { ix ++; }
Use full declarations:
unsigned char ix;
//not
char ix;
The reader, and perhaps may not remember the default or remeber it correctly
Use parenthsis not operation conventions:
c = a + ( b * c )
//not
c = a + b * c