From: "Alexei A. Frounze" Newsgroups: comp.os.msdos.djgpp Subject: Re: C++, complex, etc Date: Fri, 19 May 2000 11:03:32 +0400 Organization: MTU-Intel ISP Lines: 66 Message-ID: <3924E744.748FFFEC@mtu-net.ru> 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> NNTP-Posting-Host: ppp100-128.dialup.mtu-net.ru Mime-Version: 1.0 Content-Type: text/plain; charset=koi8-r Content-Transfer-Encoding: 7bit X-Trace: gavrilo.mtu.ru 958719813 42594 212.188.100.128 (19 May 2000 07:03:33 GMT) X-Complaints-To: usenet-abuse AT mtu DOT ru NNTP-Posting-Date: 19 May 2000 07:03:33 GMT X-Mailer: Mozilla 4.72 [en] (Win95; I) X-Accept-Language: ru,en To: djgpp AT delorie DOT com DJ-Gateway: from newsgroup comp.os.msdos.djgpp Reply-To: djgpp AT delorie DOT com "A. Sinan Unur" wrote: > > > "A. Sinan Unur" wrote: > > > what do you expect the following code to produce: > > > > > > #include > > > > > > int main(void) { > > > char c; > > > unsigned int i2; > > > unsigned int i1 = 0x12345678; > > > > > > c = (char) i1; > > > > "Alexei A. Frounze" wrote in message > news:<39242D85 DOT 6A95D430 AT mtu-net DOT ru>... > > > i1 exceeds valid range. Actually I mean values that can be represented > > by both "int" and "size_t". > > i1 is a 32-bit unsigned interger. how does it exceed the values > representable by unsigned int? That "unsigned int" exceeds valid range for "char". 8-bit "char" is unable to fit 32-bit "unsigned int". Don't ask me such questions anymore, 'coz I know math and how numbers are represented in a computer very well. :)) > > > i2 = (unsigned int) c; > > > > Don't overact. > > > > > > > > printf("i1: %8.8x\tc: %2.2x\ti2: %8.8x\n", i1, c, i2); > > > > > > return 0; > > > } > > > > > > do you think i1 == i2? > > > > Am I that stupid??? > > that wasn't what i was trying to say. all i am trying to say is this : Really? If so, Okay. > > the problem with casting an object of type size_t to int is the same as the > problem with casting an unsigned int to char. sure enough there may be > platforms where you don't loose any information in the process, but it is > not safe. what if size_t is 64 bits and int is 32 bits? casting how can > casting size_t to int be safe (even disregarding the sign issue, which is > bad enough). 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. -- Alexei A. Frounze ----------------------------------------- Homepage: http://alexfru.chat.ru Mirror: http://members.xoom.com/alexfru