What is "char const *" ? 
Author Message
 What is "char const *" ?

Dears.

I understand the difference between "const char *" and "char * const".

But what about "char const *" ?

I have a few C/C++ books and almost all of them explain both "const char *"
and "char * const". But I couldn't find any explanation for "char const *".

I wrote simple programs and tested myself, and it seems to me that compiler
treats "char const *" same as "const char *".

Am I right ? If so, why I can't find any description about "char const *".
If I was wrong, what is "char const *"?

--
From D.J. Yeo.



Fri, 07 Jan 2000 03:00:00 GMT  
 What is "char const *" ?

Quote:

> Dears.

> I understand the difference between "const char *" and "char * const".

> But what about "char const *" ?

> I have a few C/C++ books and almost all of them explain both "const char *"
> and "char * const". But I couldn't find any explanation for "char const *".

> I wrote simple programs and tested myself, and it seems to me that compiler
> treats "char const *" same as "const char *".

> Am I right ? If so, why I can't find any description about "char const *".
> If I was wrong, what is "char const *"?

The basic rule is, read declarations backwards.  So

   char const * * const *

is a pointer to a const pointer to a pointer to a const char.

For const applying to the basic type (here char), and for the
basic type only, you can choose to place it before the type.  So
the above declaration can also be written

   const char * * const *

Hth.,

- Alf

--
[Reply address intentionally foiled, but workable for humans.]



Sat, 08 Jan 2000 03:00:00 GMT  
 What is "char const *" ?


Quote:

>Dears.

Yes, sugar? ;)))

Quote:
>I understand the difference between "const char *" and "char * const".

>But what about "char const *" ?

That is equivalent to const char *. For you see, qualifiers and specifiers
may appear in any order.

Quote:
>I have a few C/C++ books and almost all of them explain both "const char *"
>and "char * const". But I couldn't find any explanation for "char const *".

Have a look at the C grammar for declarations (in, e.g., the appendix of
the K&R2).


Sat, 08 Jan 2000 03:00:00 GMT  
 
 [ 3 post ] 

 Relevant Pages 

1. Why not "const char *strerror(int);"??

2. CComBSTR into a "const char *"

3. difference between "char*" and "const char*"

4. pass "double *const *" ptr to fn expecting "const double *const *"

5. Help - encryption and "strstr(const char *1, const char *2)" problems...

6. merits of "#define", "const", and "enum" ???

7. Style question: "int const" versus "const int"

8. Help: inline char const* const& max(char const* const &a, char const* const &b)

9. I am going to study "C"

10. "I don't like const"

11. 2 meanings of "const"

12. How constant is "const"?

 

 
Powered by phpBB® Forum Software