Return Styles: Pseud0ch, Terminal, Valhalla, NES, Geocities, Blue Moon. Entire thread

How to program in C

Name: Anonymous 2010-07-19 2:21

    "If it weren't for C, we'd be writing programs in BASI, PASAL, and OBOL."

   1. Use lots of global variables.
   2. Give them cryptic names such as: X27, a_gcl, or Horace.
   3. Put everything in one large .h file.
   4. Implement the entire project at once.
   5. Use macros and #defines to emulate Pascal.
   6. Assume the compiler takes care of all the little details you didn't quite understand.
   7. Rewrite standard functions and give them your own obscure names.
   8. Use obscure, proprietary, non-portable, compiled library packages so that you never have to move from the platform you love so well.
   9. Use very descriptive comments like /* printf("Hello world\n"); */ before each function call.
  10. REMEMBER - Carriage returns are for weenies. Tabs are for those who have not reached weenie-dom yet.
  11. Include LOTS of inline assembly code.
  12. "User Interfaces" are for morons. "Users" have no business interfacing with a professional product like yours.
  13. If you are forced to comment your code (in English), then borrow comments from somebody else's code and sprinkle them throughout yours. It's quick, easy, and fun to watch people's expressions as they try to figure it out.
  14. Remember to define as many pre-processor symbols as possible in terms of already defined symbols. This is considered 'efficient use of code'.

Name: Anonymous 2010-07-19 2:35

1. Use fprintf ("fast printf") instead of printf.
2. ++i is faster than both i++ and i = i + 1.
3. void main(void) is faster than int main(void) or int main(int, char **) since no value needs to be returned to the OS.
4. Swapping with exclusive-or (a^=b^=a^=b swaps a and b) is faster than using a temporary. This works for all types (including structures), but not on all compilers. Some compilers may also give you a harmless warning.
5. Static storage duration objects are faster than automatic storage duration objects because the CPU doesn't have to set aside storage on the stack every time a function is called. Make your loop indexes global so that you can use them everywhere:
int i;
void func(void) { for (i = 0; i < 10; i++) ; /* ... */ }
void func2(void) { for (i = 0; i < 20; i++) ; /* ... */ }
/* ... */

6. Compilers often give more memory to arrays than you asked for. Here's how to check how big an array actually is (memset returns a null pointer if the size you passed to it is bigger than the size of the array you passed to it):
int arr[256];
size_t realsize;
for (realsize = 0; realsize <= SIZE_MAX; ++realsize)
        if (!memset(arr, 0, realsize)) break;
/* now you know that arr actually has realsize / sizeof (int) elements */

If you combine this with #5, your program will be faster in the long run (but this usually doesn't work for short programs).

Newer Posts
Don't change these.
Name: Email:
Entire Thread Thread List