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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 12, 20262026-06-12T19:26:21+00:00 2026-06-12T19:26:21+00:00

So I have within a program an ordinary for loop through a vector of

  • 0

So I have within a program an ordinary for loop through a vector of objects (objects that are of a type I defined, if that is relevant):

for(int k = 0; k < objects.size(); k++){ ... }

…and when I compile, I get this warning:

warning: comparison between signed and unsigned integer expressions 

This makes sense, since I think size() for a vector returns a size_t. But why would it matter? Isn’t a certain number of elements (or even memory chunks) an integer that you can count? More importantly, since my program has multiple such loops and happens to segfault a lot, could this be part of it?

  • 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-12T19:26:22+00:00Added an answer on June 12, 2026 at 7:26 pm

    The problem arises when object.size() returns a value that is greater than the maximum representable value of k. Since k is signed, it has only half the maximum value compared to a size_t1.

    Now, this may not happen in your particular application (on a typical 32-bit system, that would be upwards of two billion objects in your collection), but it’s always a good idea to use the correct types.

    1. Pre-emptive rebuttal: Yes, this is only true for machines using typical two’s-complement arithmetic, and for machines where int and size_t are represented using the same number of bits.

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

Sidebar

Related Questions

I have a big, complex MATLAB program. Somewhere within that, the number 0 is
I'm attempting to make a generic routine within my program that will instantiate objects
I have the following for loop executing within my program and I can't see
I have a Java HashHap that is getting populated within the program. For some
I have only included the code relevant to this label within the program. In
I have a search function within my program that looks for the name or
So within my program I have written a function that finds the range of
Suppose that I have a Java program within an IDE (Eclipse in this case).
I have a weird problem. I'm using pscp.exe from within a C# program (with
I have a C++ program/Linux, which within 2-3 seconds of running starts spitting error

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.