Skip to content

Instantly share code, notes, and snippets.

@andrewjkerr
Last active December 29, 2015 01:48
Show Gist options
  • Save andrewjkerr/7595340 to your computer and use it in GitHub Desktop.
Save andrewjkerr/7595340 to your computer and use it in GitHub Desktop.
A few pointers on writing in C.
/*
* In C, you cannot do the following:
* for(int i = 0; i < 5; i++){
* // do stuff
* }
*
* You must do the following:
*/
void main( void ){
int i;
for(i = 0; i < 5; i++){
// do something 5 times!
}
}
/*
* If you use a function 'b' in function 'a', you *must* either have 'b' ahead of 'a' in your code or do the following:
*/
void b(int);
void main( void ){
b();
// do stuff yo
}
void b ( int x ){
// woah you do some stuff here too!
}
/*
* Here's a pointer on pointers :)
*/
#define LATCH_ADDR 0x4000
void main( void ){
// let's write 0x22 to our latch!
unsigned int* latch = (unsigned int*) LATCH_ADDR;
*latch = 0x22;
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment