www.delorie.com/archives/browse.cgi   search  
Mail Archives: djgpp/2000/05/18/16:14:39

From: "Alexei A. Frounze" <alex DOT fru AT mtu-net DOT ru>
Newsgroups: comp.os.msdos.djgpp
Subject: Re: C++, complex, etc
Date: Thu, 18 May 2000 23:38:48 +0400
Organization: MTU-Intel ISP
Lines: 42
Message-ID: <392446C8.61533B8F@mtu-net.ru>
References: <Pine DOT SUN DOT 3 DOT 91 DOT 1000518184200 DOT 15189T-100000 AT is> <8g1l6o DOT 3vs4qnf DOT 0 AT buerssner-17104 DOT user DOT cis DOT dfn DOT de>
NNTP-Posting-Host: ppp96-62.dialup.mtu-net.ru
Mime-Version: 1.0
X-Trace: gavrilo.mtu.ru 958678737 94564 212.188.96.62 (18 May 2000 19:38:57 GMT)
X-Complaints-To: usenet-abuse AT mtu DOT ru
NNTP-Posting-Date: 18 May 2000 19:38:57 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

Dieter Buerssner wrote:
> 
> Eli Zaretskii wrote:
> 
> >On Thu, 18 May 2000, Alexei A. Frounze wrote:
> >> > In general, you don't want to assign int to size_t or vice versa.
> >> > Mixing signed and unsigned means trouble.
> >>
> >> If I'm 100% sure my "int" is positive (greater or equal 0 and less than
> >> INT_MAX), will I have problems?
> >
> >No, in that case it will work, assuming that sizeof(int) <=
> >sizeof(size_t).
> 
> This test (sizeof(int) <= sizeof(size_t)) probalbly is sufficient for
> all C implementations (at least the ones know). But it is not enough
> from the C Standard. size_t could have padding bits. The correct test
> would be (after including limits.h) INT_MAX <= SIZE_MAX.
> 
> So, to answer Alexei's question: When your int is <= SIZE_MAX and >= 0,
> you can savely assign it to a varible of size_t. If a varible of size_t
> (or, say the return value of strlen) is <= INT_MAX, you can savely
> assign it to a varible of type int.

Stop! There are SSIZE_MAX and _POSIX_SSIZE_MAX defined only. Are those
constants limits for size_t, right?

> To answer an other question of Alexei (from memory): "Do people
> mix up size_t and int?" I have done it, but try to avoid it now.
> Often, it will be no trouble at all. I.e. you read input with fgets
> and a buffer smaller than 2^15. Then the return of strlen is guaranteed
> to be representable as an int.

ok.

bye.
-- 
Alexei A. Frounze
-----------------------------------------
Homepage: http://alexfru.chat.ru
Mirror:   http://members.xoom.com/alexfru

- Raw text -


  webmaster     delorie software   privacy  
  Copyright © 2019   by DJ Delorie     Updated Jul 2019