• Open Menu Close Menu
  • Apple
  • Shopping Bag
  • Apple
  • Mac
  • iPad
  • iPhone
  • Watch
  • TV
  • Music
  • Support
  • Search apple.com
  • Shopping Bag

Lists

Open Menu Close Menu
  • Terms and Conditions
  • Lists hosted on this site
  • Email the Postmaster
  • Tips for posting to public mailing lists
Re: const StringPtr != ConstStringPtr
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: const StringPtr != ConstStringPtr


  • Subject: Re: const StringPtr != ConstStringPtr
  • From: David Fang <email@hidden>
  • Date: Tue, 10 Jan 2006 14:23:03 -0500 (EST)

> During the conversion of our projects from CW to Xcode, I got errors
> on all calls that passed a constant string to functions that take a
> const StringPtr. If ConstStringPtr is a typedef of const unsigned
> char* and StringPtr is a typedef of unsigned char*, then why does
> Xcode (or gcc rather) think they're different?
>
> void Func(const StringPtr s);
>
> Func("\pblah"); <--error

If you expand the typedefs, you'll see why they are not the same:

StringPtr is a pointer to char

ConstStringPtr is a pointer to const char,
	the pointer itself is mutable, but the pointee (char) is
	read-only.

const StringPtr is a const pointer to char,
	that is, the pointer is const (immutable) while the pointee (char)
	remains modifiable.

const ConstStringPtr is a const pointer to const char

In your example, Func expects a const pointer to a modifiable string,
however, you pass it a const char[], which is a non-writable string,
hence the error.

constness was not always respected in C type-checking, but is always
checked in C++ type-checking.  This might explain why another compiler (in
C mode) may not have caught the constness error before.

HTH.

David Fang

 _______________________________________________
Do not post admin requests to the list. They will be ignored.
Xcode-users mailing list      (email@hidden)
Help/Unsubscribe/Update your Subscription:

This email sent to email@hidden

  • Follow-Ups:
    • Re: const StringPtr != ConstStringPtr
      • From: Steve Mills <email@hidden>
References: 
 >const StringPtr != ConstStringPtr (From: Steve Mills <email@hidden>)

  • Prev by Date: Re: Debugger can't find correct source file
  • Next by Date: Xcode 2.2 and Intel
  • Previous by thread: const StringPtr != ConstStringPtr
  • Next by thread: Re: const StringPtr != ConstStringPtr
  • Index(es):
    • Date
    • Thread