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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 31, 20262026-05-31T14:35:17+00:00 2026-05-31T14:35:17+00:00

I’ve been trying to get rid of warnings in some older code (must use

  • 0

I’ve been trying to get rid of warnings in some older code (must use MSVC 2005, currently working with a 32 bit build), but have been struggling to get rid of a size_t to unsigned int conversion warning. We have our own Array<T> implementation of a growing array that implements an

template<typename I> const T& at(const I i) const {return atImpl(i);}

method. When called as

size_t i = 10; myArray.at(i);

I get a conversion from 'size_t' to 'const unsigned int', possible loss of data warning. A working theory has been that I is understood to be unsigned int, which is causing compiler to cast/convert the size_t to unsigned int when passing i to at (which would have been inconvenient but acceptable). However, I haven’t been able to reproduce this warning in neither a minimal working example (bottom of this post), nor in more complex minimal examples. Simply casting the parameter to unsigned int makes the warning disappear and would be enough for our needs (by contract, the number fits within an unsigned int)

  1. Is my understanding about I being unsigned int in such a call correct (spec says “A typedef-name is thus a synonym for another type. A typedef-name does
    not introduce a new type
    “, typeid(size_t(1)).name() says unsigned int and size_t seems to be typedeffed). In other words, should or should not the minimal example give the warning? The build configuration is the same, as far as I can tell.
  2. As our code gives us warnings and the minimal example doesn’t, there’s something I must be overlooking. Despite all effort, I can’t figure out what. Ideas?

Thanks

The minimal example:

    template<typename T>
    class A
    {
      int t;
    public:
      template<typename I> T& at(const I i) { return t;}  
    };

    int main()
    {  
      size_t i = 10;
      A<int> a; 
      a.at(i) = 5; // no warning, why?
      return 0;
    }
  • 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-31T14:35:18+00:00Added an answer on May 31, 2026 at 2:35 pm

    The at function is also templated. C++ will try to deduce the template type argument. Which is what is happening in your code since you are not specifying the type in the call such as a.at< size_t>(1);

    This code will generate a warning because it has deduced the type as a unsigned int and then we try to pass an size_t

    template <typename T>
    class A
    {
        int t;
        public:
            template<typename I> T& at(const I i)
            { return t;}
    };
    
    int main()
    {
        unsigned int j = 5;
        size_t i = 10;
        A<int> a;
    
        a.at(j) = 4; // deduce template type as unsigned int
        a.at(i) = 5; // generate warning
        return 0;
    }
    

    EDIT: I actually tried this code in VS and it generates the warning.

    Edit2: In the code I tried size_t and unsigned int are both also 4 bytes. So I did some digging. In older versions of VS size_t is defined as typedef __w64 unsigned int size_t The ‘__w64’ is now deprecated but was used to flag types that would have a different size (eg 64 vs 32) when moving to a 64 bit platform. The __w64 causes the compiler to see size_t as a different type.

    As an experiment I typedefed my own unsigned int myint and changed the line size_t i = 10 to myint i = 10.

    using typedef __w64 unsigned int myint generates the warning where as ‘typedef unsigned int myint` does not generate a warning.

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

Sidebar

Related Questions

I am trying to understand how to use SyndicationItem to display feed which is
I want use html5's new tag to play a wav file (currently only supported
I'm trying to use string.replace('’','') to replace the dreaded weird single-quote character: ’ (aka
I have a jquery bug and I've been looking for hours now, I can't
link Im having trouble converting the html entites into html characters, (&# 8217;) i
I have just tried to save a simple *.rtf file with some websites and
For some reason, after submitting a string like this Jack’s Spindle from a text
Basically, what I'm trying to create is a page of div tags, each has
I have a string like this: La Torre Eiffel paragonata all&#8217;Everest What PHP function
I have this code to decode numeric html entities to the UTF8 equivalent character.

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.