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.

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.

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

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?
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.

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?
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

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...

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.

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.

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

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.

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.