|
From: Ioannis V. <no...@ya...> - 2001-10-22 19:39:30
|
> -----Original Message----- > From: KJK::Hyperion [mailto:no...@li...]=20 > Sent: Monday, October 22, 2001 6:08 PM > To: Ioannis Vranos > Subject: RE: [Dev-C++] Errorhandling > > only in C code or C-minded C++ code. In C++ you use one of=20 > the countless=20 > string classes and you're done, they allow embedded nulls and=20 > whatsoever=20 > since they generally have a length field. Heck, even OLE's=20 > BSTR does, and=20 > it's a plain struct Now all these are details but we must clear details. :) Yes i strongly agree with you, in C++ code we should use standard library object and containers not low level (dangerous) C stuff. >=20 > Even in the case, it MAY at most cause memory leaks (strlen=20 > returns less=20 > chars than actually allocated), but only if the compiler=20 At most it can cause anything depending on how our code thinks on doing things. We could depend on sizeof to get the length of the string (wrong approach), write some code performing for example binary search with the possibility to encounter the last '\0; instead of the first, and this because we assume the string has only one '\0'. The ways to screw up are infinite. :) The most important thing to think is that we must not use the form "string\0". :) > allocates string=20 > literals as variants, something it SHOULDN'T do (string=20 > literals SHOULD be=20 > considered constants). Else the incriminated strings remain=20 We were talking about C stuff ( strcat(buffer, "string\0"); where our "string\0" would be added to string stored in buffer. String literals of course must not be dealt as variables. > exactly the=20 > same, untouched, and the extra null is ignored >=20 In case of strcat() operatios the extra null is ignored but i am talking for troubles in general. Ioannis * Ioannis Vranos * Programming pages: http://www.noicys.f2s.com * Alternative URL: http://run.to/noicys |