
Here are a few tips and tricks for the C Programming language that you may use.
General
1. Timer - When you need to display the time for how long a piece of code took to execute.
2. Comment out blocks of code - This is used to tell why a piece of code is not being used anymore.
3. Macro Tips - Watch out for these things when you’re using Macros.
4. Factorial - Use NOT to calculate factorials.
5. Powx - This is the quick exponentiation function.
6. Saturated Addition - Use this for when you’re adding numbers but want to make sure that the total doesn’t overflow.
7. FNV Hash - Use this when you need to hash large amounts of data.
8. Seeding rand() - Seeding random number generators for returning different values everytime.
String Handling
1. Check if two strings are equal - Checking whether strings are equal or not.
2. Stringise Preprocessor Arguments - Insert an arguments to a macro within a string.
3. Text Editing - It is better to use a text editor from the environment that writing one of your own.
4. Display Time - Use this to display time in a easier format than displaying huge number of seconds.
5. Temporary Return Buffer - Return char* without any leaks.
Data Structures
1. Intro to bitwise operations - Learn how to use bitwise operations.
2. Count Bits - Find the number of bits that have been sent in an unsigned int.
3. Binary Constants - These are macros that allow you to use binary constants directly in your code.
4. Digit Mask - Use this macro in order to pull out one digit from a particular number.
5. Bit Manipulation - This will be used in order to test, flip and set individual bits.
6. Coordinate compression - You can turn multidimensional array units into one int using this.
Debugging
1. Debug Messages - The pre-processor can be used in order to compile in debugging messages.
2.Assert - Assert is a standard library function. This function tells you in which line of which file it failed at. The value passed to assert needs to be zero for this though.
3. #error - Want to create your own compile errors? This is how.
4. GDB - This is an introduction to using the GNU debugger.
Author : Shivam Kotwalia, CodeKill
No comments:
Post a Comment