• If you are citizen of an European Union member nation, you may not use this service unless you are at least 16 years old.

  • Get control of your email attachments. Connect all your Gmail accounts and in less than 2 minutes, Dokkio will automatically organize your file attachments. You can also connect Dokkio to Drive, Dropbox, and Slack. Sign up for free.



Page history last edited by Kenneth Finnegan 12 years, 2 months ago

This page is a dumping ground for tips that might be too small to warrent their own page, or are just that plain and simple, or are just still half-baked.


Read Code

Read code, read code, and read more code.  You'll pick up twice as many tricks reading good code than you ever will reading some lackys website. (Not that you should stop reading this!)

Never Repeat Yourself

If you see yourself copy and paste more than 3 lines of code, you should put it inside a new function.

What Does This Function Do?!?

At the beginning of every function, have a block comment explaining in full plain english what each parameter means, and what it returns.  Include failure cases to test for and any other helpful info.

Protect Casts

When you convert one type into another smaller type (ie int to short), first use an assert to make sure you're not overflowing, unless that's ok.

#include <assert.h>

#include <limits.h>

int foo = 1000000;

assert(foo <= SHRT_MAX && foo >= SHRT_MIN);

short bar = (short) foo;

External Links

http://c-faq.com/index.html - comp.lang.c FAQ

https://www.securecoding.cert.org/confluence/display/seccode/CERT+C+Secure+Coding+Standard - CERT standard for secure coding in C

http://www.abarnett.demon.co.uk/tutorial.html - A good tutorial on optimizing your code

http://publications.gbdirect.co.uk/c_book/ - An entire book posted online for free








Comments (0)

You don't have permission to comment on this page.