From: Hans-Bernhard Broeker Newsgroups: comp.os.msdos.djgpp Subject: Re: C++, complex, etc Date: 19 May 2000 09:34:19 GMT Organization: Aachen University of Technology (RWTH) Lines: 30 Message-ID: <8g31qr$b33$1@nets3.rz.RWTH-Aachen.DE> References: <3923BA11 DOT AD387617 AT mtu-net DOT ru> <8g15d8$nl9$1 AT news01 DOT cit DOT cornell DOT edu> <39242D85 DOT 6A95D430 AT mtu-net DOT ru> <8g23d1$6qp$1 AT news01 DOT cit DOT cornell DOT edu> <3924E744 DOT 748FFFEC AT mtu-net DOT ru> NNTP-Posting-Host: acp3bf.physik.rwth-aachen.de X-Trace: nets3.rz.RWTH-Aachen.DE 958728859 11363 137.226.32.75 (19 May 2000 09:34:19 GMT) X-Complaints-To: abuse AT rwth-aachen DOT de NNTP-Posting-Date: 19 May 2000 09:34:19 GMT Originator: broeker@ To: djgpp AT delorie DOT com DJ-Gateway: from newsgroup comp.os.msdos.djgpp Reply-To: djgpp AT delorie DOT com Alexei A. Frounze wrote: > Suppose we have a string. If the string is definetely shorter than INT_MAX > and SSIZE_MAX (say less than 32000 characters), there must be everything > okay with type casting for strlen(), strncpy(), etc. *If*. But in general, you can never know that it's shorter than 32000 characters. Especially not if you're just calling strlen() to find out how long it is. Casting the return value of strlen() to int would mean that you never learn how long that string actually was. The problem with the type cast is that you cannot know wether it was safe, after you've done it: you're throwing away information that may have been vitally important. Assuming that all strings are shorter than INT_MAX is a bad idea. You should not let yourself get into the habit of making that assumption. It may be true for the program you're just writing, where you know how big all the strings can possibly be. But once you start writing your programs that way, sooner or later you will introduce a bug in one of your programs, because you made that assumption where it was *not* true. And you'll have a very hard time finding that bug, because your way of thinking, by then, will have been fixed. You'll have forgotten that size_t would have been the cleaner solution. After all: what *is* so bad about size_t in your opinion that makes you try to avoid it like the plague? Using it you'ld have one nasty detail less to worry about. -- Hans-Bernhard Broeker (broeker AT physik DOT rwth-aachen DOT de) Even if all the snow were burnt, ashes would remain.