Skip to content

Instantly share code, notes, and snippets.

@cmcbride
Created May 14, 2011 22:45
Show Gist options
  • Star 1 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save cmcbride/972723 to your computer and use it in GitHub Desktop.
Save cmcbride/972723 to your computer and use it in GitHub Desktop.
C const
// This is a slight modification of the original at:
// http://www.cap-lore.com/Languages/const.c
//
// Does "int const *" refer to a constant pointer, or a constant integer?
// The following shows what gcc thinks.
// gcc 4 rejects any of the lines below that are commented out.
typedef const int * cip;
typedef int const * icp;
typedef int * const ipc;
typedef int const * const icpc;
int xx(const int x){return x+3;}
//int xy(const int x){return (++x)+3;}
//int xy(int const x){return (++x)+3;}
int xcipa(cip x){return *x+3;}
int xcipb(cip x){return *(++x)+3;}
//int xcipc(cip x){return ++(*x)+3;}
int xicpa(icp x){return *x+3;}
int xicpb(icp x){return *(++x)+3;}
//int xicpc(icp x){return ++(*x)+3;}
int xipca(ipc x){return *x+3;}
//int xipcb(ipc x){return *(++x)+3;}
int xipcc(ipc x){return ++(*x)+3;}
int xicpca(icpc x){return *x+3;}
// int xicpcb(icpc x){return *(++x)+3;}
// int xicpcc(icpc x){return ++(*x)+3;}
// Thus 'const' refers to the thing on its left, if any.
// Otherwise on its right.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment