Re: cvs commit: src/lib/libc/sys tls.2

看板DFBSD_commit作者時間21年前 (2005/03/22 04:01), 編輯推噓0(000)
留言0則, 0人參與, 最新討論串6/20 (看更多)
: :On Mon, 21 Mar 2005 11:15:32 -0800 (PST) :Matthew Dillon <dillon@apollo.backplane.com> wrote: : :> Grumble (Matt goes off in a corner and mumbles about stupid standards :> which use unsigned ints because some bozo wanted to write 2.1GB of data :> in one go, when they really ought to just use normal ints). : :Why ought they do that? : :(or: why would one ever want a *negative* infosize?!) : :-Chris It's not that, it's the same issue with sizeof() returning unsigned when it really just ought to return an int. Unsigned quantities change the way expressions in code are handled in ways that are not always apparent. For example, if you are doing a delta calculation you can't just do the calculation and check to see if the result is negative, instead you have to do a range check before you do the calculation. Things like that. Negative numbers are also very useful as a means of representing out of band data or conditions. EOF == -1 is a good example. Another is the handling of an optional argument. If 0 is an allowed value then you can initialize an option to -1 to indicate that it has not been issued. so, e.g. an optional 'int size_opt' argument, instead of 'int size; int size_opt_is_valid;'. But with size_t you then have to cast it to an unsigned. It just makes life unnecessarily difficult when 99.9999% of the calls to all these routines never need to specify huge blocks. In the case of a memory block, I suppose 'long' would be a better choice then 'int', but I really hate the way the hidden unsignedness of size_t and sizeof() has infiltrated the standards. -Matt Matthew Dillon <dillon@backplane.com>
文章代碼(AID): #12FoW800 (DFBSD_commit)
討論串 (同標題文章)
文章代碼(AID): #12FoW800 (DFBSD_commit)