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 8354465
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 9, 20262026-06-09T09:33:25+00:00 2026-06-09T09:33:25+00:00

What is the point of having a seperate unsigned type, aka NSUInteger if there

  • 0

What is the point of having a seperate unsigned type, aka NSUInteger if there is no guarantee (nor even, it seems, a chance) that you can assume, bet your bottom dollar on, or cry yourself to sleep for – what the name implies – an inherently nonnegative result.

NSUInteger normal = 5;
NSUInteger freaky = normal - 55;
NSLog(@"%ld, %ld", normal, freaky);

NSLOG 5, -50

Sure, I can bend over backwards trying to get zero, or some kind of normalized value…

NSUInteger nonNeg = (((normal - 55) >= 0) ? (normal - 55) : 0);

PARRALELUNIVERSELOG 5, -50

But here the compiler complains.. rightfully so that comparison of unsigned expression >= 0 is always true – and there it is, an answer I didn’t want / expect. Someone slap my face, get me a drink, an tell me what year it is.. or better yet… how to make it – you know – not do that.

  • 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-09T09:33:27+00:00Added an answer on June 9, 2026 at 9:33 am

    %ld tells NSLog to print it as a signed integer. Try %lu.

    See 2’s Complement on wikipedia for an explanation of what’s going on at the bit level.

    What is happening here is that subtraction is causing the unsigned integer representation to wrap-around. To protect against this you need to check before you do the subtraction.

    NSUInteger x = 5; 
    NSUInteger y = 55;
    
    // If 0 makes sense in your case
    NSUInteger result = (x >= y) ? (x - y) : 0; 
    
    // If it should be an error
    if(x < y)
    {
        // Report error
    }
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

Perhaps I'm having a Post-Ballmer-Peak Moment . I'm hoping that someone can help point
I'm having trouble understanding the point of clojure's Noir library. It seems to be
I'm having a problem getting this test case to work. Can anyone point me
What is the point of having enum SomeEnum : byte // <---- { SomeValue
I am having trouble skipping to a certain point in a Vimeo video clip
I am having issues, could you point me in the right direction? EDIT: This
by simple I mean, having buttons: bold, italic, numbered list bullet point list indent
I've just started graphics programming in Ogre, and just can't understand why there is
With MVC3, should I design my view models such that there is one that
-- EDIT -- Worth to point out. While having a problem with different homework

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.