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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 28, 20262026-05-28T15:25:25+00:00 2026-05-28T15:25:25+00:00

I have a piece of code where I see a warning saying I am

  • 0

I have a piece of code where I see a warning saying

I am doing a comparison between signed and unsigned number .
Something like int <= CONSTANT/sizeof(expression)

What is the best way to correct this? I believe to take the modulus of signed number and then do the comparison, right? I mean I get the unsigned number after division by sizeof operator on an expression. So the other way could be to make this rhs signed

If so is there a function in c that would let me do this? I did a quick search and they say % for modulo which obviously is not what I am looking for.

This is the actual warning

warning: comparison between signed and unsigned integer expressions

and this is the actual line of code

functionA( ……, int num, …..) {

assert( num <= MAX_SIZE/sizeof(int));//where MAX_SIZE is #define
MAX_SIZE 1000

}

  • 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-05-28T15:25:26+00:00Added an answer on May 28, 2026 at 3:25 pm

    Just cast one side to the other signedness. You have to make sure that the signed number is not negative if you cast that to unsigned – otherwise a comparison of -1 < 100 will not have the desired outcome, since (unsigned)(-1) == UINT_MAX -, or that the unsigned number doesn’t overflow if you cast that to signed. In those cases, add an additional condition to treat them.

    For the above particular case, I would use

    assert(num <= (int)(MAX_SIZE/sizeof(int)));
    // num <= MAX_SIZE/(int)sizeof(int) if I'm in a mean mood
    

    if num might be negative and

    assert((unsigned)num <= MAX_SIZE/sizeof(int));
    

    if num is guaranteed to be nonnegative.

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

Sidebar

Related Questions

I have a piece of code like this: <div id=container runat=server> <div id=parent runat=server>
I have this piece of code using standard sockets: void set_fds(int sock1, int sock2,
I have written a piece of code to see if the record is already
I have a piece of code that is checking to see if a session
I have this piece of code in C: int q = 10; int s
I have a piece of code that checks to see if a macro is
I have a piece of code looking like this: start <- getCPUTime (_, _,
If I have a piece of code like this: $get_categories = mysql_query(SELECT * FROM
Here I have piece of code, showing example of how I want to update
I have this piece of code in a function. I want to print the

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.