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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 14, 20262026-05-14T15:38:58+00:00 2026-05-14T15:38:58+00:00

In general, I want warnings of unsigned vs signed. However, in this particular case,

  • 0

In general, I want warnings of unsigned vs signed.

However, in this particular case, I want it suppressed;

std::vector<Blah> blahs;

for(int i = 0; i < blahs.size(); ++i) { ...

I want to kill this comparison.

Thanks!

(using g++)

  • 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-14T15:38:59+00:00Added an answer on May 14, 2026 at 3:38 pm

    You should fix, not suppress. Use an unsigned type:

    for (size_t i = 0; i < blahs.size(); ++i)
    

    You can also use unsigned, but size_t is more appropriate here (and may have a different, larger, range). If you’re only using i to iterate and don’t need its value in the loop, use iterators instead:

    for (auto iter = blahs.begin(), end = blahs.end(); iter != end; ++iter)
    

    If your compiler does not support auto, replace auto with T::iterator or T::const_iterator, where T is the type of blahs. If your compiler supports a fuller subset of C++11, though, do this:

    for (auto& element : blahs)
    

    Which is best of all.


    Strictly speaking, the above is not “correct”. It should be:

    typedef std::vector<Blah> blah_vec;
    blah_vec blahs;
    
    for (blah_vec::size_type i = 0; i < blahs.size(); ++i)
    

    But this can be verbose, and every implementation I know uses size_t as size_type anyway.


    If for some reason you really need a signed integer type for i, you’ll have to cast:

    // assumes size() will fit in an int
    for (int i = 0; i < static_cast<int>(blahs.size()); ++i)
    
    // assumes i will not be negative (so use an unsigned type!)
    for (int i = 0; static_cast<size_t>(i) < blahs.size(); ++i)
    
    // and the technically correct way, assuming i will not be negative
    for (int i = 0; static_cast<blah_vec::size_type>(i) < blahs.size(); ++i)
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

i just want to know a general information about this particular information. Any good
This question has been asked before in a more general way. I want to
This is a design question, rather than a technical one. General case : I
It seems I still don't get generics ... I want a general function to
We want to compare general performance (CPU, I/O, network, ...) of different JVMs for
I want to make a general error handling package that should be called from
I want to know the General formula for Writing Regular Expression? Any article?
I have one very general object that I want to map to a destination
We have an application that we want to make available to the general internet-using
When I am trying to make an overarching vector of shapes and in this

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.