May 24, 2005
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
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
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
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
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
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
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
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 25, 2005
"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
"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.