Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 8015279
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 4, 20262026-06-04T20:12:38+00:00 2026-06-04T20:12:38+00:00

I found some code similar to the following: BOOL hasValue_:1; – (BOOL) hasValue {

  • 0

I found some code similar to the following:

BOOL hasValue_:1;

- (BOOL) hasValue {
    return !!hasValue_;
}

- (void) setHasValue:(BOOL) value {
    hasValue_ = !!value;
}

I’m wondering why the double exclamation points are necessary? Are we not already passing BOOL to the method and returning BOOL? Is BOOL really a typedef for an int?

Thanks!

EDIT
Thanks for all of the responses thus far. I understand that using !! with other data types effectively performs some typecasting to a boolean result. However, in the example above, I’m strictly working with BOOL already.

EDIT
If I’m working with a BOOL already, why is it necessary to normalize it to a 0 for false and 1 for true? Doesn’t a BOOL guarantee that it is false for 0 and true for everything else?

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-04T20:12:39+00:00Added an answer on June 4, 2026 at 8:12 pm

    I’m wondering why the double exclamation points are necessary?

    BOOL is a signed char, or a char posing as a boolean type via typedef. It will happily represent any integer in the range [SCHAR_MIN...SCHAR_MAX]. The double exclamation point applies a boolean NOT operation twice, which effectively converts the original value to an int of 0 or 1, narrowing the value to the range of boolean.

    But there’s a twist: BOOL hasValue_:1; declares a single-bit bitfield representation. It can represent two values. return !!hasValue_; is not needed. However, it is needed to correctly narrow when going from signed char (BOOL) to one bit.

    Are we not already passing BOOL to the method and returning BOOL?

    Nope. It’s a signed char. !!value reduces input values to YES or NO.

    If I’m working with a BOOL already, why is it necessary to normalize it to a 0 for false and 1 for true?

    Doesn’t a BOOL guarantee that it is false for 0 and true for everything else?

    BOOL is a signed char. A typedef of signed char does not make this guarantee.

    C99 (which has been available for you to use for many years when targeting osx or ios) has a more useful boolean type representation (bool). Unfortunately, BOOL remains in regular use in objc for historical reasons. Personally, I use BOOL only when necessary (e.g. overriding).

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I found some mapkit code on the internet that looks like this: - (void)recenterMap
i found some code which is using anchor tags in eval eval(a='http://google.co.in'+window .location.href); The
I found some code for an rss reader. And I want to use it
I have found some code snippet in the internet. But it is missing some
I have found some code on measuring execution time here http://www.dreamincode.net/forums/index.php?showtopic=24685 However, it does
I just opened a file in IDA Pro and I found some code that
I am new to vbscript and while reading i found some code as Do
I got a task to maintain a c# project, I found some code like
I've just found some C++ code (at http://msdn.microsoft.com/en-us/library/k8336763(VS.71).aspx ), which uses a technique I've
I've found some C# code online to impersonating a user and it appears to

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.