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

  • You already know Dokkio is an AI-powered assistant to organize & manage your digital files & messages. Very soon, Dokkio will support Outlook as well as One Drive. Check it out today!



Page history last edited by Kenneth Finnegan 15 years, 11 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.