On Mon, Oct 28, 2002 at 04:54:26AM +0000, Dharmender Rai wrote: > const char * some_ptr; > // is same as > char * const some_ptr; > // You can think in this way: > /* In the later one, const is used for some_ptr that > is a pointer to char. So here the pointer is constant. > In the former case also you have made ( char *) as > constant :). So they are the same > */ No. Quoting from Peter van der Linden's book Expert C Programming, page 66: A declaration involving a pointer and a const has several possible orderings: const int * grape; int const * grape; int * const grape_jelly; The last of these cases makes the pointer read-only, whereas the other two make the object that it points at read-only; and of course, both the object and what it points at might be constant. Either of the following equivalent declarations will accomplish this: const int * const grape_jam; int const * const grape_jam; Quoting further, on page 74: If a const and/or volatile keyword is next to a type specifier (e.g., int, long, etc.) it applies to the type specifier. Otherwise the const and/or volatile keyword applies to the pointer asterisk on its immediate left. Much as Christine recommends Linux Device Drivers, 2nd edition (a good book! :) I heartily recommend van der Linden's Expert C Programming. ISBN 0-13-177429. Best $40 I've spent. Sure, it has a horribly ugly orange cover, but that just helps you find the book in the pile next to your bed late at night when your eyes are getting blurry and you know you should be asleep but some silly C question is driving you out of your mind. -- "There's an old saying in Tennessee, i know it's in Texas, probably in Tennessee, that says, 'Fool me once... shame on ... shame on .. you; but fool--you can't get fooled again.'" -- Commander in Chief of the US Military
Attachment:
pgp00191.pgp
Description: PGP signature