• 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
More 'bool' weirdness
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

More 'bool' weirdness


  • Subject: More 'bool' weirdness
  • From: Jens Alfke <email@hidden>
  • Date: Fri, 14 Jun 2013 15:58:31 -0700

OK, now I’ve hit a situation where the C99 ‘bool’ type is behaving weirdly. The following snippets all compile without errors or warnings:

	bool foo = @“huh”;

	bool foo = [NSMutableArray array];

	bool x = &x;

	static bool test(void) { return &test; }

In general it seems to be legal to assign any pointer or integer value to a LHS of type bool. But try this with BOOL or with any integer type, and you get an error. (If you try to assign a float to a bool, you do get an error about an implicit conversion.)

The only explanation I can think of is that when assigning to bool the compiler adds the same implicit “!= 0” test that it does if you put a non-bool expression in an if() or while() test … but that’s nuts. It’s totally not the right thing to do here; it’s more likely to just hide bugs (as it was doing in my code.)

—Jens
 _______________________________________________
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: More 'bool' weirdness
      • From: Jeffrey Walton <email@hidden>
    • Re: More 'bool' weirdness
      • From: Scott Ribe <email@hidden>
  • Prev by Date: Every other simulator launch fails
  • Next by Date: Re: Every other simulator launch fails
  • Previous by thread: Re: Every other simulator launch fails
  • Next by thread: Re: More 'bool' weirdness
  • Index(es):
    • Date
    • Thread