Path: csiph.com!news.mixmin.net!eternal-september.org!reader01.eternal-september.org!.POSTED!not-for-mail From: Keith Thompson Newsgroups: comp.lang.c++ Subject: Re: Type conversion for hundreds of lines Date: Wed, 12 Oct 2022 14:30:53 -0700 Organization: None to speak of Lines: 26 Message-ID: <87fsfs4tma.fsf@nosuchdomain.example.com> References: MIME-Version: 1.0 Content-Type: text/plain Injection-Info: reader01.eternal-september.org; posting-host="40a80e675ec1aea557807be1b777153a"; logging-data="1673789"; mail-complaints-to="abuse@eternal-september.org"; posting-account="U2FsdGVkX1/VumzOvxH/fV4qP/VkAvc4" User-Agent: Gnus/5.13 (Gnus v5.13) Emacs/27.2 (gnu/linux) Cancel-Lock: sha1:3NKjFtMO4uS0fb97WOfXngrp9y0= sha1:j/P2u+2SS7lNPcovtgYMendcx+M= Xref: csiph.com comp.lang.c++:86891 JiiPee writes: > I have been pondering this many times. I keep it short: > If I have hundreds of lines like this: > > short a; > std::vector v; > ... > a = v.size(); > > This gives a warning: "warning, assigning size_t to short". > I know this can be fixed: > a = static_cast(v.size()); > > but if we have hundreds of those lines, how would you fix this? Place > a static cast in all of them? Of create some helper funktion to do > this? Why is `a` defined as a short and not as a size_t? If there's a very good reason that `a` *needs* to be a short, it makes sense to consider some kind of cast. If not, just make it a size_t. -- Keith Thompson (The_Other_Keith) Keith.S.Thompson+u@gmail.com Working, but not speaking, for Philips void Void(void) { Void(); } /* The recursive call of the void */