Home | Contact Us | FAQ | Search & Site Map | Link to Us
Sign In | Join | Other 45 Sites in Network
Home
Discussion Groups
General
GeneralPortable MacsHardwareNetworking
Applications
Mac ApplicationsEudoraFirefox / MozillaInternet ExplorerOutlook ExpressMS OfficeEntourageExcelPowerPointWordVirtual PCMedia PlayerOther MS Products
Programming
Mac ProgrammingCodeWarriorPerl
Country Specific
Australian Mac GroupUK Mac Group

Mac Forum / Programming / CodeWarrior / July 2003



Tip: Looking for answers? Try searching our database.

Not sure why this is an error

Thread view: 
Enable EMail Alerts  Start New Thread
Thread rating: 
Gerry - 11 Jul 2003 02:24 GMT
I have a function which has one argument defined as

const unsigned char **

(a list of pointers to Pascal strings)

When I pass a pointer to a Str255 or even when I pass an actual unsigned
char **, the compiler gives me this error:

Error   : illegal implicit conversion from 'unsigned char **' to
'const unsigned char **'

When I remove the 'const' from the function, it compiles fine.

Why would the 'const' prevent me from passing the unsigned char **?

Signature

gbeggs@Canada.com   http://www3.sympatico.ca/~gbeggs/

David Phillip Oster - 11 Jul 2003 03:08 GMT
> I have a function which has one argument defined as
>
[quoted text clipped - 7 lines]
> Error   : illegal implicit conversion from 'unsigned char **' to
> 'const unsigned char **'

a pointer to a const-unsigned-char-pointer is not the same as
a pointer to an unsigned-char-pointer

It isn't even default convertable to one. You need to read up on
the meaning of the keyword "const" in C++ in Scott Meyers' and
Herb Sutter's books (and so do I.)
Gerry - 11 Jul 2003 05:16 GMT
> a pointer to a const-unsigned-char-pointer is not the same as
> a pointer to an unsigned-char-pointer
>
> It isn't even default convertable to one. You need to read up on
> the meaning of the keyword "const" in C++ in Scott Meyers' and
> Herb Sutter's books (and so do I.)

I don't think of what I have as a
pointer-to-const-unsigned-char-pointer.
I was thinking of it as a const-pointer-to-pointer-to-unsigned-char.

If that makes any sense.

What would be the best way to define an unsigned char ** to be read-only
then? (So that I could pass an unsigned char ** without problems)

Signature

gbeggs@Canada.com   http://www3.sympatico.ca/~gbeggs/

Miro Jurisic - 11 Jul 2003 06:26 GMT
> I don't think of what I have as a
> pointer-to-const-unsigned-char-pointer.
[quoted text clipped - 4 lines]
> What would be the best way to define an unsigned char ** to be read-only
> then? (So that I could pass an unsigned char ** without problems)

Read it right to left.

char *
        pointer to char
char const *
        pointer to constant character
const char *
        pointer to character constant == char const *
char * const
        constant pointer to character
char const * const
        constant pointer to constant character
const char * const
        constant pointer to character constant == char const * const

char * *
        pointer to pointer to character
char const * *
const char * *
        pointer to pointer to constant character
char * const *
        pointer to constant pointer to character
char * * const
        constant pointer to pointer to character
char const * const *
const char * const *
        pointer to constant pointer to constant character
char const * * const
const char * * const
        constant pointer to pointer to constant character
char * const * const
        constant pointer to constant pointer to character
char const * const * const
const char * const * const
        constant pointer to constant pointer to constant character

conar char * volatile & const
        constant reference to volatile pointer to constant character

You get the idea.

So, if you want const pointer to pointer to unsigned char, you want

unsigned char * * const

However, that's almost certainly not what you mean, because you probably mean a
pointer to a const pointer to unsigned char. "const pointer" means the pointer
itself can't change, whereas I suspect you mean "pointer to const" which means
that the pointee can't change, so that would be

unsigned char * const *

hth

meeroh
Gerry - 11 Jul 2003 06:56 GMT
> You get the idea.
>
[quoted text clipped - 8 lines]
>
> unsigned char * const *

Wow Thanks :)
That's a bit of an eye opener.

I've always found the way C defines types a bit confusing when it gets
beyond the trivial.

Signature

gbeggs@Canada.com   http://www3.sympatico.ca/~gbeggs/

 
Sign In
Join
My Latest Posts
My Monitored Threads
My Blog
My Photo Gallery
My Profile
My Homepage

Start New Thread
Enable EMail Alerts
Rate this Thread



©2009 Advenet LLC   Privacy Policy - Terms of Use
This website includes both content owned or controlled by Advenet as well as content owned or controlled by third parties.