From: "A. Sinan Unur" Newsgroups: comp.os.msdos.djgpp Subject: Re: C++, complex, etc Date: Thu, 18 May 2000 20:54:37 -0400 Organization: http://unur.com/ Lines: 54 Sender: verified_for_usenet AT cornell DOT edu (asu1 on ip6.ithaca.ny.pub-ip.psi.net) Message-ID: <8g23d1$6qp$1@news01.cit.cornell.edu> 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> NNTP-Posting-Host: ip6.ithaca.ny.pub-ip.psi.net X-Trace: news01.cit.cornell.edu 958697697 7001 38.10.16.6 (19 May 2000 00:54:57 GMT) X-Complaints-To: usenet AT news01 DOT cit DOT cornell DOT edu NNTP-Posting-Date: 19 May 2000 00:54:57 GMT X-Priority: 3 X-MSMail-Priority: Normal X-Newsreader: Microsoft Outlook Express 5.00.2919.6600 X-MIMEOLE: Produced By Microsoft MimeOLE V5.00.2919.6600 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: > > 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? > > > 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 : 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). ------------------------ A. Sinan Unur Department of Policy Analysis and Management, Cornell University, Ithaca, NY 14853, USA. mailto:sinan AT unur DOT com http://unur.com/sinan/