TIP: Click on subject to list as thread! ANSI
echo: c_echo
to: Roy J. Tellason
from: Pascal Schmidt
date: 2004-01-20 18:26:18
subject: [C] (Thanks)An interesting question

Hi Roy! :-)

 RJT> Sure.  But my point is,  if you're dealing with a number that's 
 RJT> _never_ going to go negative (because such a thing wouldn't make any 
 RJT> sense) then isn't it good practice to say so,  in the source code?
It is. Unless you have to compare it against a signed value somewhere. That
can lead to compiler warning if you have all warnings turned on (for gcc,
it's not in the default set of warning that get turned on with -Wall).

That can easily happen. For example, if you store the number of bytes you
want to write to file in an unsigned int (because it cannot be negative)
and then compare that against the return value of read(2). read returns
ssize_t, a signed value, because it wants to return -1 on error.

Most of the time you want to use fread(3) anyway, which returns an unsigned
number, so you can avoid such problems by using the proper library
functions. 

 RJT> Yep,  nothing's quite nailed down unless you start fiddling around 
 RJT> with sizeof and similar nonsense.  :-)
Using sizeof is preferable to hard-coding sizes, yes. But one needs to be
careful with pointers. ;)

Ciao
Pascal

--- Msged/LNX 6.1.1
* Origin: rot13: tr '[A-Za-z]' '[N-ZA-Mn-za-m]' (1:153/401.2)
SEEN-BY: 633/267 270
@PATH: 153/401 307 140/1 106/2000 633/267

SOURCE: echomail via fidonet.ozzmosis.com

Email questions or comments to sysop@ipingthereforeiam.com
All parts of this website painstakingly hand-crafted in the U.S.A.!
IPTIA BBS/MUD/Terminal/Game Server List, © 2025 IPTIA Consulting™.