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

  • Stop wasting time looking for files and revisions! Dokkio, a new product from the PBworks team, integrates and organizes your Drive, Dropbox, Box, Slack and Gmail files. Sign up for free.

View
 

GrabBag

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

 

http://www.cppreference.com/

http://arcterex.ufies.org/c_notes.html

http://www.cprogramming.com/tips/

http://www.tek-tips.com/threadminder.cfm?pid=205

http://www.nsftools.com/tips/CTips.htm

http://mycplus.blogspot.com/2008/03/top-programming-tips-for-c-programmers.html

Comments (0)

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