On 9 October 2012 18:22, Anthony Toft wrote: > Not sure that I've ever wanted a const pointer other than "int p[2];" > > What would you use it for? > We can make sure a function never screws up a pointer causing hard to debug bugs... For example: void foo ( int * const p ) { *p =3D 1234; // works great p++; // hey, we do not want to do that! Error! } main () { int myInt; int anotherInt; foo ( &myInt ); foo ( &anotherInt ); } $ gcc -o testConstPointer testConstPointer.c testConstPointer.c: In function =91foo=92: testConstPointer.c:5: error: increment of read-only location > > -----Original Message----- > From: piclist-bounces@mit.edu [mailto:piclist-bounces@mit.edu] On Behalf > Of > V G > Sent: Tuesday, October 09, 2012 20:04 > To: Microcontroller discussion list - Public. > Subject: Re: [OT] C/C++ pointer syntax > > Another case. What if you want to declare a const pointer like so: int * > const p;? > > int *const p; looks weird, and it's illogical. How would you even go abou= t > trying to justify why the asterisk is touching the const keyword? > > int* const p; looks better. > > int * const p; looks the best > -- > http://www.piclist.com PIC/SX FAQ & list archive View/change your > membership > options at http://mailman.mit.edu/mailman/listinfo/piclist > > > -- > http://www.piclist.com PIC/SX FAQ & list archive > View/change your membership options at > http://mailman.mit.edu/mailman/listinfo/piclist > --=20 int main() { char *a,*s,*q; printf(s=3D"int main() { char *a,*s,*q; printf(s=3D%s%s%s, q=3D%s%s%s%s,s,q,q,a=3D%s%s%s%s,q,q,q,a,a,q); }", q=3D"\"",s,q,q,a=3D"\\",q,q,q,a,a,q); } --=20 http://www.piclist.com PIC/SX FAQ & list archive View/change your membership options at http://mailman.mit.edu/mailman/listinfo/piclist .