Thread overview | |||||||||||||||||||||||
---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|
|
May 23, 2005 dmd 125 - is this a bug? | ||||
---|---|---|---|---|
| ||||
the following code import std.random, std.stdio; int main() { rand_seed(0,0); for (int i = 0; i < 10; i++) writefln(rand()); } outputs... 3333243700 473838585 2856274370 1850229479 3777857304 3173865323 2116055926 3788284210 3873632863 598163586 Error: AssertError Failure random(10) ?? I don't get it. |
May 23, 2005 Re: dmd 125 - is this a bug? | ||||
---|---|---|---|---|
| ||||
Posted in reply to clayasaurus | Maybe it asserts that subsequent values be different :-) ....Just kidding... |
May 23, 2005 Re: dmd 125 - is this a bug? | ||||
---|---|---|---|---|
| ||||
Posted in reply to clayasaurus | clayasaurus wrote:
> the following code
>
> import std.random,
> std.stdio;
>
> int main()
> {
> rand_seed(0,0);
>
> for (int i = 0; i < 10; i++)
> writefln(rand());
> }
>
> outputs...
>
> 3333243700
> 473838585
> 2856274370
> 1850229479
> 3777857304
> 3173865323
> 2116055926
> 3788284210
> 3873632863
> 598163586
> Error: AssertError Failure random(10)
>
> ?? I don't get it.
Ok, I've found out that if I add a return 0 at the end it doesn't assert.
Here is the simplest test case...
int main() {}
|
May 23, 2005 Re: dmd 125 - is this a bug? | ||||
---|---|---|---|---|
| ||||
Posted in reply to Lionello Lunesu | Lionello Lunesu wrote:
> Maybe it asserts that subsequent values be different :-)
> ....Just kidding...
>
>
bah... rand_seed(getUTCtime(), 0) then : )
|
May 23, 2005 Re: dmd 125 - is this a bug? | ||||
---|---|---|---|---|
| ||||
Posted in reply to clayasaurus | > Ok, I've found out that if I add a return 0 at the end it doesn't assert.
>
> Here is the simplest test case...
>
> int main() {}
That's the compiler being nice and asserting that you should return something when you exit a function that is declared to return something. This has come up before so I'd poke around in the archives for more background.
|
May 23, 2005 Re: dmd 125 - is this a bug? | ||||
---|---|---|---|---|
| ||||
Posted in reply to clayasaurus | "clayasaurus" <clayasaurus@gmail.com> wrote in message news:d6t0lq$1i1d$1@digitaldaemon.com... > Error: AssertError Failure random(10) > > ?? I don't get it. The code "falls of the end" and doesn't have a return statement. Hence, the compiler inserts an assert. Try compiling with -w. |
May 23, 2005 Re: dmd 125 - is this a bug? | ||||
---|---|---|---|---|
| ||||
Posted in reply to Walter | IMHO, it'd be release nice if the assert could have a tiny bit more information attached to it... e.g. "function exit without return value."
-[Unknown]
>>Error: AssertError Failure random(10)
>
> The code "falls of the end" and doesn't have a return statement. Hence, the
> compiler inserts an assert. Try compiling with -w.
|
May 23, 2005 Re: dmd 125 - is this a bug? | ||||
---|---|---|---|---|
| ||||
Posted in reply to Unknown W. Brackets | Unknown W. Brackets wrote:
> IMHO, it'd be release nice if the assert could have a tiny bit more information attached to it... e.g. "function exit without return value."
>
> -[Unknown]
>
>
>>> Error: AssertError Failure random(10)
>>
>>
>> The code "falls of the end" and doesn't have a return statement. Hence, the
>> compiler inserts an assert. Try compiling with -w.
It would be nice if assert could take a char[] so you can give a nice message like... assert(false, "assert description...");
and have a message like
Error: AssertError Failure random(10) : assert description...
|
May 24, 2005 Re: dmd 125 - is this a bug? | ||||
---|---|---|---|---|
| ||||
Posted in reply to clayasaurus | "clayasaurus" <clayasaurus@gmail.com> wrote in message news:d6tohj$2abi$1@digitaldaemon.com... > It would be nice if assert could take a char[] so you can give a nice message like... assert(false, "assert description..."); > > and have a message like > > Error: AssertError Failure random(10) : assert description... It's a common request. Assertion failures are for the developer, not the end user. They give the file/line of the assert that tripped. Any comments about what went wrong should be in the comments next to the assert. I am not seeing why it should be put into the executable, it just seems redundant. |
May 24, 2005 Re: dmd 125 - is this a bug? | ||||
---|---|---|---|---|
| ||||
Posted in reply to Walter | That's odd. You know this is illegal at compile time. So make it an error. No? L. "Walter" <newshound@digitalmars.com> wrote in message news:d6t52f$1ml0$1@digitaldaemon.com... > > "clayasaurus" <clayasaurus@gmail.com> wrote in message news:d6t0lq$1i1d$1@digitaldaemon.com... >> Error: AssertError Failure random(10) >> >> ?? I don't get it. > > The code "falls of the end" and doesn't have a return statement. Hence, > the > compiler inserts an assert. Try compiling with -w. > > |
Copyright © 1999-2021 by the D Language Foundation