www.digitalmars.com         C & C++   DMDScript  

digitalmars.D.bugs - dmd 125 - is this a bug?

reply clayasaurus <clayasaurus gmail.com> writes:
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
next sibling parent reply "Lionello Lunesu" <lio lunesu.removethis.com> writes:
Maybe it asserts that subsequent values be different :-)
....Just kidding... 
May 23 2005
parent clayasaurus <clayasaurus gmail.com> writes:
Lionello Lunesu wrote:
 Maybe it asserts that subsequent values be different :-)
 ....Just kidding... 
 
 
bah... rand_seed(getUTCtime(), 0) then : )
May 23 2005
prev sibling next sibling parent reply clayasaurus <clayasaurus gmail.com> writes:
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
parent reply "Ben Hinkle" <bhinkle mathworks.com> writes:
 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
parent reply "Lionello Lunesu" <lio lunesu.removethis.com> writes:
If the _compiler_ would have been nice, he'd have mentioned it while 
compiling :-)
This is just the compiler being nasty and inserting an assert(0) in your 
code.

L.

"Ben Hinkle" <bhinkle mathworks.com> wrote in message 
news:d6t3pt$1l9d$1 digitaldaemon.com...
 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 24 2005
parent reply Derek Parnell <derek psych.ward> writes:
On Tue, 24 May 2005 10:33:05 +0300, Lionello Lunesu wrote:

 If the _compiler_ would have been nice, he'd have mentioned it while 
 compiling :-)
 This is just the compiler being nasty and inserting an assert(0) in your 
 code.
Not really. It gives you control over whether or not to issue an error in this situation. If you want to be told about these situations, compile using the "-w" switch. -- Derek Parnell Melbourne, Australia 24/05/2005 7:56:09 PM
May 24 2005
next sibling parent reply clayasaurus <clayasaurus gmail.com> writes:
Derek Parnell wrote:
 On Tue, 24 May 2005 10:33:05 +0300, Lionello Lunesu wrote:
 
 
If the _compiler_ would have been nice, he'd have mentioned it while 
compiling :-)
This is just the compiler being nasty and inserting an assert(0) in your 
code.
Not really. It gives you control over whether or not to issue an error in this situation. If you want to be told about these situations, compile using the "-w" switch.
The only problem I have with the -w switch is that it stops giving warnings after the first few, so you are forced to fix the warnings if you want more.
May 24 2005
parent Derek Parnell <derek psych.ward> writes:
On Tue, 24 May 2005 12:54:51 +0000, clayasaurus wrote:

 Derek Parnell wrote:
 On Tue, 24 May 2005 10:33:05 +0300, Lionello Lunesu wrote:
 
 
If the _compiler_ would have been nice, he'd have mentioned it while 
compiling :-)
This is just the compiler being nasty and inserting an assert(0) in your 
code.
Not really. It gives you control over whether or not to issue an error in this situation. If you want to be told about these situations, compile using the "-w" switch.
The only problem I have with the -w switch is that it stops giving warnings after the first few, so you are forced to fix the warnings if you want more.
Yes, I agree that this is a big nuisance. I think that Walter regards "warning" as just another type of "error" ;-) -- Derek Parnell Melbourne, Australia 25/05/2005 7:22:41 AM
May 24 2005
prev sibling parent reply Stewart Gordon <smjg_1998 yahoo.com> writes:
Derek Parnell wrote:
 On Tue, 24 May 2005 10:33:05 +0300, Lionello Lunesu wrote:
 
 If the _compiler_ would have been nice, he'd have mentioned it while 
 compiling :-)
 This is just the compiler being nasty and inserting an assert(0) in your 
 code.
Not really. It gives you control over whether or not to issue an error in this situation. If you want to be told about these situations, compile using the "-w" switch.
Why doesn't DMD, in its default configuration, report _all_ _errors_? How can int qwert() {} possibly be what the programmer meant? http://www.digitalmars.com/drn-bin/wwwnews?digitalmars.D.bugs/3817 Stewart. -- My e-mail is valid but not my primary mailbox. Please keep replies on the 'group where everyone may benefit.
May 24 2005
next sibling parent Derek Parnell <derek psych.ward> writes:
On Tue, 24 May 2005 18:00:55 +0100, Stewart Gordon wrote:

 Derek Parnell wrote:
 On Tue, 24 May 2005 10:33:05 +0300, Lionello Lunesu wrote:
 
 If the _compiler_ would have been nice, he'd have mentioned it while 
 compiling :-)
 This is just the compiler being nasty and inserting an assert(0) in your 
 code.
Not really. It gives you control over whether or not to issue an error in this situation. If you want to be told about these situations, compile using the "-w" switch.
Why doesn't DMD, in its default configuration, report _all_ _errors_? How can int qwert() {} possibly be what the programmer meant? http://www.digitalmars.com/drn-bin/wwwnews?digitalmars.D.bugs/3817
I don't know. I was just trying to give Walter the benefit of the doubt. I too think that *obvious* mistakes like that need to be considered in the same light as " if ( whatever ) ;" -- Derek Parnell Melbourne, Australia 25/05/2005 7:24:23 AM
May 24 2005
prev sibling parent "Walter" <newshound digitalmars.com> writes:
"Stewart Gordon" <smjg_1998 yahoo.com> wrote in message
news:d6vmk7$1r82$1 digitaldaemon.com...
 Why doesn't DMD, in its default configuration, report _all_ _errors_?
 How can

      int qwert() {}

 possibly be what the programmer meant?

 http://www.digitalmars.com/drn-bin/wwwnews?digitalmars.D.bugs/3817
There was a loooong thread about that not so long ago...
May 25 2005
prev sibling parent reply "Walter" <newshound digitalmars.com> writes:
"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
next sibling parent reply "Unknown W. Brackets" <unknown simplemachines.org> writes:
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
parent reply clayasaurus <clayasaurus gmail.com> writes:
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 23 2005
parent reply "Walter" <newshound digitalmars.com> writes:
"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 23 2005
parent "Unknown W. Brackets" <unknown simplemachines.org> writes:
That's true; in many cases, the file and line will be all that's needed. 
  However, there are times when that is not the case:

1. When the compiler inserts an assertion automatically, it can be 
confusing without a short description.

2. In an open source environment, where a third-party developer may have 
patched or greatly modified his source, making it hard to match up line 
numbers (this is worse if you leave asserts/dbc on for a release or 
beta, which isn't completely uncommon.)

In any case, if I had the option to include a comment for asserts, I 
still wouldn't use it all of the time.  But, there are cases where I 
would want to be able to put some text there.

I guess a solution would be an exception thrown only in debug mode, 
which takes __FILE__ and __LINE__...

-[Unknown]


 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
prev sibling parent reply "Lionello Lunesu" <lio lunesu.removethis.com> writes:
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.
May 24 2005
parent reply Derek Parnell <derek psych.ward> writes:
On Tue, 24 May 2005 10:30:18 +0300, Lionello Lunesu wrote:

 "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.
 That's odd. You know this is illegal at compile time. So make it an error.
 No?
Because there are some circumstances in which it is not illegal, and other cases in which the compiler might not be able to work it out without a lot of overhead. I can't think of any, but I believe that Walter has provided examples in the past. -- Derek Parnell Melbourne, Australia 24/05/2005 7:49:33 PM
May 24 2005
parent reply "Walter" <newshound digitalmars.com> writes:
"Derek Parnell" <derek psych.ward> wrote in message
news:oyymcsk1f6ui.xr10jgtac4ra$.dlg 40tude.net...
 On Tue, 24 May 2005 10:30:18 +0300, Lionello Lunesu wrote:

 "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.
 That's odd. You know this is illegal at compile time. So make it an
error.
 No?
Because there are some circumstances in which it is not illegal, and other cases in which the compiler might not be able to work it out without a lot of overhead. I can't think of any, but I believe that Walter has provided examples in the past.
The easiest example is: int test(Collection x) { foreach (int i; x) if (foo(i)) return i; } Is foreach guaranteed by the algorithm to never terminate? The compiler can't tell. Being forced to insert a return statement at the end will be confusing and misleading to the maintenance programmer. This, with many pros and cons, was hashed out in great detail a few months ago.
May 25 2005
parent Stewart Gordon <smjg_1998 yahoo.com> writes:
Walter wrote:
<snip>
 The easiest example is:
 
 int test(Collection x)
 {
     foreach (int i; x)
         if (foo(i))
             return i;
 }
 
 Is foreach guaranteed by the algorithm to never terminate? The compiler
 can't tell. Being forced to insert a return statement at the end will be
 confusing and misleading to the maintenance programmer. This, with many pros
 and cons, was hashed out in great detail a few months ago.
Is it me, or are you talking at cross purposes with the rest of us? You give an example of a function that may or may not encounter a return statement. A decent number of us are talking about functions that have no return statements in them at all. Was I imagining it, or did the compiler use to catch these? Stewart. -- My e-mail is valid but not my primary mailbox. Please keep replies on the 'group where everyone may benefit.
May 26 2005