🚀 go-pugleaf

RetroBBS NetNews Server

Inspired by RockSolid Light RIP Retro Guy

Article View: borland.public.cppbuilder.nativeapi
Article #2118

Re: Extremely slow string functions

#2118
From: Bob Gonder
Date: Fri, 06 Apr 2007 14:56
20 lines
1577 bytes
Thomas Maeder [TeamB] wrote:

>> #include <stdlib.h>

>>  return (int)rand()*(int)rand()+(int)rand();
>
>More importantly, the expression may overflow, in which case your
>program has undefined behavior.

Ummm, I think the maximum calculated value is 3FFF 8000, which is
positive, and doesn't overflow unless int is 16bit.

Replace rand() with RAND_MAX and you get
	RAND_MAX * RAND_MAX + RAND_MAX

For easier manual calculation:
	RAND_MAX * (RAND_MAX+1)
	7FFF * 8000 = 3FFF8000

Perhaps you were thinking of _lrand which returns a 31 bit value.
Technical Details
Message-ID: <eimc13peu65012pvnnsrvlhr2p22c3qm0e@4ax.com>
Path: arc1-ca.pugleaf.net!g2news1.google.com!news1.google.com!border1.nntp.dca.giganews.com!border2.nntp.dca.giganews.com!nntp.giganews.com!newspeer1.nwr.nac.net!newsfeeds.ihug.co.nz!ihug.co.nz!newsgroups.borland.com!not-for-mail
References: <46161b72@newsgroups.borland.com> <m2wt0pli2a.fsf@glue.ch>

Show Full Headers
Complete Article Headers
X-Google-Thread: 10cc67,cb6147be69a44149
X-Google-Attributes: gid10cc67,public
X-Google-Language: ENGLISH,ASCII-7-bit
From: Bob Gonder <notbg@notmindspring.invalid>
Newsgroups: borland.public.cppbuilder.nativeapi
Subject: Re: Extremely slow string functions
Date: Fri, 06 Apr 2007 07:56:45 -0700
Organization: MindSpring Enterprises, Inc.
Reply-To: notbg@notmindspring.invalid
Message-ID: <eimc13peu65012pvnnsrvlhr2p22c3qm0e@4ax.com>
References: <46161b72@newsgroups.borland.com> <m2wt0pli2a.fsf@glue.ch>
X-Newsreader: Forte Agent 1.93/32.576 English (American)
MIME-Version: 1.0
Content-Type: text/plain; charset=us-ascii
Content-Transfer-Encoding: 7bit
NNTP-Posting-Host: 69.69.80.223
X-Trace: newsgroups.borland.com 1175871403 69.69.80.223 (6 Apr 2007 07:56:43 -0800)
Lines: 22
Path: arc1-ca.pugleaf.net!g2news1.google.com!news1.google.com!border1.nntp.dca.giganews.com!border2.nntp.dca.giganews.com!nntp.giganews.com!newspeer1.nwr.nac.net!newsfeeds.ihug.co.nz!ihug.co.nz!newsgroups.borland.com!not-for-mail