Path: csiph.com!eternal-september.org!reader02.eternal-september.org!.POSTED!not-for-mail From: Tim Rentsch Newsgroups: comp.lang.c++ Subject: Re: This code is effective for modest-sized numbers, but can you tell what it does? Date: Tue, 24 May 2022 05:43:32 -0700 Organization: A noiseless patient Spider Lines: 48 Message-ID: <86leur14p7.fsf@linuxsc.com> References: <0c3601f0-fc8c-4bb9-a8b3-598ea1ca4a79n@googlegroups.com> <86fsm18i1c.fsf@linuxsc.com> <86mtfp4gjw.fsf@linuxsc.com> MIME-Version: 1.0 Content-Type: text/plain; charset=us-ascii Injection-Info: reader02.eternal-september.org; posting-host="6d60e850df502405df1b0fa46dc1963d"; logging-data="19509"; mail-complaints-to="abuse@eternal-september.org"; posting-account="U2FsdGVkX19rBsY2vnh+Wu1CT70CtGe/Ydh87k7aBYU=" User-Agent: Gnus/5.11 (Gnus v5.11) Emacs/22.4 (gnu/linux) Cancel-Lock: sha1:R5PstdbNAmMRTek2sedMlDBU2T0= sha1:000GBWb5ipfnarDfjkC84CbVFcY= Xref: csiph.com comp.lang.c++:84253 scott@slp53.sl.home (Scott Lurndal) writes: > Tim Rentsch writes: > >> Paavo Helde writes: >> >>> 25.04.2022 15:27 Tim Rentsch kirjutas: >>> >>>> Juha Nieminen writes: >>>> >>>>> Graeme C. wrote: >>>> >>>> [...] >>>> >>>>>> for (int i=0; i>>>> >>>>> std::vector::size() returns a value of type std::size_t. You >>>>> shouldn't be using an int with it. >>>> >>>> I don't want to start a holy war, but in this particular case >>>> there is no problem comparing a signed type to a size_t (which is >>>> an unsigned type). >>> >>> I don't really care if such code uses signed or unsigned types. >>> However, there is a problem when comparing signed and unsigned >>> types, namely the gcc compiler issues warnings for them with -Wall, >>> and sometimes these warnings are actually useful. >> >> IME these warnings from gcc give false positives too often to >> be used on every single compile. Of course it can be useful >> to turn them on now and then, to make sure nothing is askew, >> but trying to avoid them even in all the false positive cases >> is IMO more trouble than it is worth. > > I beg to differ. We include -Wall and -Werror on all compiles > (well over 2 million lines of C/C++). This sounds like you are offering an implicit argument that because your group does it all the time it follows that it's a good idea. I don't find such an argument convincing in any way. > It is far too common for C programmers to use 'int' when > the domain of the value doesn't include negative numbers. Such cases would still be caught if the signed/unsigned warnings were turned on only before every code review rather than on every single compile.