Created
May 14, 2011 22:45
-
-
Save cmcbride/972723 to your computer and use it in GitHub Desktop.
C const
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// 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