From owner-freebsd-scsi@FreeBSD.ORG Tue Jun 3 12:12:41 2003 Return-Path: Delivered-To: freebsd-scsi@freebsd.org Received: from mx1.FreeBSD.org (mx1.freebsd.org [216.136.204.125]) by hub.freebsd.org (Postfix) with ESMTP id 159F237B401 for ; Tue, 3 Jun 2003 12:12:41 -0700 (PDT) Received: from magic.adaptec.com (magic-mail.adaptec.com [208.236.45.100]) by mx1.FreeBSD.org (Postfix) with ESMTP id 270A143F85 for ; Tue, 3 Jun 2003 12:12:40 -0700 (PDT) (envelope-from gibbs@scsiguy.com) Received: from redfish.adaptec.com (redfish.adaptec.com [162.62.50.11]) by magic.adaptec.com (8.11.6/8.11.6) with ESMTP id h53J7aZ28320; Tue, 3 Jun 2003 12:07:36 -0700 Received: from [10.100.253.70] (aslan.btc.adaptec.com [10.100.253.70]) by redfish.adaptec.com (8.8.8p2+Sun/8.8.8) with ESMTP id MAA27735; Tue, 3 Jun 2003 12:12:37 -0700 (PDT) Date: Tue, 03 Jun 2003 13:13:21 -0600 From: "Justin T. Gibbs" To: Kern Sibbald Message-ID: <955950000.1054667601@aslan.btc.adaptec.com> In-Reply-To: <1054660763.13630.279.camel@rufus> References: <3EDB31AB.16420.C8964B7D@localhost> <3EDB59A4.27599.C93270FB@localhost> <20030602110836.H71034@beppo> <577540000.1054579840@aslan.btc.adaptec.com> <20030602131225.F71034@beppo> <1054645616.13630.161.camel@rufus> <20030603072944.U44880@beppo> <1054652678.13630.209.camel@rufus> <882210000.1054657530@aslan.btc.adaptec.com> <1054658432.13630.252.camel@rufus> <900070000.1054659860@aslan.btc.adaptec.com> <1054660763.13630.279.camel@rufus> X-Mailer: Mulberry/3.0.3 (Linux/x86) MIME-Version: 1.0 Content-Type: text/plain; charset=us-ascii Content-Transfer-Encoding: 7bit Content-Disposition: inline cc: freebsd-scsi@freebsd.org cc: mjacob@feral.com Subject: Re: SCSI tape data loss X-BeenThere: freebsd-scsi@freebsd.org X-Mailman-Version: 2.1.1 Precedence: list Reply-To: "Justin T. Gibbs" List-Id: SCSI subsystem List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , X-List-Received-Date: Tue, 03 Jun 2003 19:12:41 -0000 >> > By the way, the funny casting is mandatory in C++, >> > because ssize_t as returned by the write is not the >> > same as size_t (what is written). > > If I remove the (uint32_t) cast, I get an error message: > > c++ -c -I. -I.. -g -O2 -Wall block.c > block.c: In function `int write_block_to_dev (JCR *, DEVICE *, > DEV_BLOCK *)': > block.c:381: warning: comparison between signed and unsigned integer > expressions > > Line 381 reads: > > if ((stat=write(dev->fd, block->buf, (size_t)wlen)) != wlen) { > > so I will stick with my funny casting. > This has nothing to do with type size or the fact that you are using C++. The same warning would occur when your code is compiled as C. wlen should be a signed type. Since wlen by definition cannot be larger than the largest positive integer reportable by the signed return value of write, using an unsigned type buys you nothing. Conversion from ssize_t to size_t will occur without error if you happen to chose to make wlen an ssize_t. I guess it matters little. My own philosophy is that casts should be used as a last resort rather than deployed indiscriminantly to cover up compile warnings. The above casts are easily avoidable which is why I mentioned them at all. -- Justin