• 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: "'char' type is unsigned" seems to be broken
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: "'char' type is unsigned" seems to be broken


  • Subject: Re: "'char' type is unsigned" seems to be broken
  • From: Chris Espinosa <email@hidden>
  • Date: Tue, 10 May 2005 08:43:35 -0700

On May 10, 2005, at 6:14 AM, Clark Cox wrote:

On 5/9/05, Brian Barnes <email@hidden> wrote:


Turning on "'char' type is unsigned" and running this code:


     char            txt[256];

     unsigned char    txt2[256];


     strcpy(txt,"abc");

     strcpy(txt2,"abc");


gets you:


warning: pointer targets in passing argument 1 of 'strcpy' differ in

signedness


For the first line.


"-funsigned-char" is in the compile arguments.  Once again, I'm using

-fast, this might be breaking it.



Though the message is a bit off, I'd argue that this is actually

correct. Even if 'char' is unsigned, it is still a type that is

distinct from 'unsigned char'. 'unsigned char*' is not implicitly

convert-able to 'char*'. In fact, the following code:


int main()

{

  char          *cp   = 0;

  unsigned char *ucp  = 0;

  signed char   *scp  = 0;


  ucp = cp; //8

  scp = cp; //9

  cp = ucp; //10

  cp = scp; //11


  return 0;

}


Produces the following diagnostics when compiled with g++-4.0

(regardless of the signedness of plain char), and rightly so:

test.cpp: In function `int main()':

test.cpp:8: error: invalid conversion from 'char*' to 'unsigned char*'

test.cpp:9: error: invalid conversion from 'char*' to 'signed char*'

test.cpp:10: error: invalid conversion from 'unsigned char*' to 'char*'

test.cpp:11: error: invalid conversion from 'signed char*' to 'char*'


Clark is correct.  If you really want to generate possibly erroneous code without complaints from the compiler, you should pass -Wno-sign-compare in your warning flags (it's enabled by -W and -Wall, you may want to turn those off).  There's a check box for this warning in the Gnu C/C++ Compiler > Warnings collection in your target's Build Settings.

Chris

 _______________________________________________
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

References: 
 >"'char' type is unsigned" seems to be broken (From: Brian Barnes <email@hidden>)
 >Re: "'char' type is unsigned" seems to be broken (From: Clark Cox <email@hidden>)

  • Prev by Date: Re: Codewarrior ->Xcode port
  • Next by Date: Re: XCode/xcodebuild problems...
  • Previous by thread: Re: "'char' type is unsigned" seems to be broken
  • Next by thread: Re: "'char' type is unsigned" seems to be broken
  • Index(es):
    • Date
    • Thread