Thread overview | |||||||||||||||
---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|
|
December 05, 2005 Error: AssertError Failure | ||||
---|---|---|---|---|
| ||||
Hello everyone! :-D OK, look at my code: ------------------------ import std.c.windows.windows; extern (Windows) bool Beep(uint, uint); int main(char[][] args) { Beep(100, 100); } ------------------------ It compiles witn no errors, but when I run it: Error: AssertError Failure test.d(8) Anyonw know why? Thanks! ;-) |
December 05, 2005 Re: Error: AssertError Failure | ||||
---|---|---|---|---|
| ||||
Posted in reply to Kixdemp | "Kixdemp" <Kixdemp_member@pathlink.com> wrote in message news:dn0c1i$2iun$1@digitaldaemon.com... > It compiles witn no errors, but when I run it: > > Error: AssertError Failure test.d(8) > > Anyonw know why? Thanks! ;-) You've defined main() to return an int, but you never return anything. Instead of a compiler error, D makes a return-value-less function a runtime error. More than once I've wished that the error message would be a little more specific.. |
December 05, 2005 Re: Error: AssertError Failure | ||||
---|---|---|---|---|
| ||||
Posted in reply to Jarrett Billingsley | On Sun, 04 Dec 2005 22:30:16 -0500, Jarrett Billingsley <kb3ctd2@yahoo.com> wrote:
> "Kixdemp" <Kixdemp_member@pathlink.com> wrote in message
> news:dn0c1i$2iun$1@digitaldaemon.com...
>> It compiles witn no errors, but when I run it:
>>
>> Error: AssertError Failure test.d(8)
>>
>> Anyonw know why? Thanks! ;-)
>
> You've defined main() to return an int, but you never return anything.
> Instead of a compiler error, D makes a return-value-less function a runtime
> error. More than once I've wished that the error message would be a little
> more specific..
>
Compile with -w
|
December 05, 2005 Re: Error: AssertError Failure | ||||
---|---|---|---|---|
| ||||
Posted in reply to Chris Miller | In article <op.s1aj50qapo9bzi@dialup-4.157.44.14.dial1.boston1.level3.net>, Chris Miller says... > >On Sun, 04 Dec 2005 22:30:16 -0500, Jarrett Billingsley <kb3ctd2@yahoo.com> wrote: > >> "Kixdemp" <Kixdemp_member@pathlink.com> wrote in message news:dn0c1i$2iun$1@digitaldaemon.com... >>> It compiles witn no errors, but when I run it: >>> >>> Error: AssertError Failure test.d(8) >>> >>> Anyonw know why? Thanks! ;-) >> >> You've defined main() to return an int, but you never return anything. >> Instead of a compiler error, D makes a return-value-less function a >> runtime >> error. More than once I've wished that the error message would be a >> little >> more specific.. >> > >Compile with -w Thanks very much! ;-) |
December 05, 2005 Re: Error: AssertError Failure | ||||
---|---|---|---|---|
| ||||
Posted in reply to Chris Miller | Chris Miller schrieb: > On Sun, 04 Dec 2005 22:30:16 -0500, Jarrett Billingsley <kb3ctd2@yahoo.com> wrote: > >> "Kixdemp" <Kixdemp_member@pathlink.com> wrote in message news:dn0c1i$2iun$1@digitaldaemon.com... >>> It compiles witn no errors, but when I run it: >>> >>> Error: AssertError Failure test.d(8) >>> >>> Anyonw know why? Thanks! ;-) >> >> You've defined main() to return an int, but you never return anything. >> Instead of a compiler error, D makes a return-value-less function a >> runtime >> error. More than once I've wished that the error message would be a >> little >> more specific.. I agree! Something like "ERROR: no return value" would be much nicer! Tiago -- Tiago Gasiba (M.Sc.) - http://www.gasiba.de Everything should be made as simple as possible, but not simpler. |
December 05, 2005 Re: Error: AssertError Failure | ||||
---|---|---|---|---|
| ||||
Posted in reply to Tiago Gasiba | Tiago Gasiba wrote: >>>>Error: AssertError Failure test.d(8) >>>> >>>>Anyonw know why? Thanks! ;-) >>> >>>You've defined main() to return an int, but you never return anything. >>>Instead of a compiler error, D makes a return-value-less function a >>>runtime >>>error. More than once I've wished that the error message would be a >>>little >>>more specific.. > > I agree! Something like "ERROR: no return value" would be much nicer! The compiler just inserts an "assert(0);" line, and assert doesn't allow for any such messages... e.g. assert(false,"no return at end of function"); func.c(689): if (global.params.warnings) { printf("warning - "); error("no return at end of function"); } if (global.params.useAssert && !global.params.useInline) { /* Add an assert(0); where the missing return * should be. */ e = new AssertExp(endloc, new IntegerExp(0, 0, Type::tint32)); } else e = new HaltExp(endloc); Side note: in the above code you can see that if you use -inline, then you'll get a "halt" instead! Same if you use -release, which disables all asserts. This is an oft-requested D feature, that assert() is allowed to take messages too. You can do this in Java, for instance: http://java.sun.com/j2se/1.4.2/docs/guide/lang/assert.html But so far it has been rejected, for D... I think it's similar to "Access Violation", which isn't guarded especially for either. In Java, you would get a NullPointerException with the stack trace of the callers (catchable). In D, it's time to bring out the debugger... Don't think it's going to change any time soon: source file/line it is. (In the original posting, the AssertError does point to the "}" line...) I just think Walter prefers* the "hard" errors, pointing to the source ? --anders * http://www.digitalmars.com/drn-bin/wwwnews?digitalmars.D/2165 http://www.digitalmars.com/drn-bin/wwwnews?digitalmars.D/14466 |
December 05, 2005 Re: Error: AssertError Failure | ||||
---|---|---|---|---|
| ||||
Posted in reply to Anders F Björklund |
> Don't think it's going to change any time soon: source file/line it is. (In the original posting, the AssertError does point to the "}" line...)
>
> I just think Walter prefers* the "hard" errors, pointing to the source ?
Indeed, he does. And although I have created an "assert2(int,const char*)" myself in my current project, I have to agree with Walter on this one.
What would be handy though is the expression appearing in the assert error message. Then you could write "int no_return_value; assert(no_return_value);" and the printed message would contain "no_return_value" as a hint.
L.
|
December 05, 2005 Re: Error: AssertError Failure | ||||
---|---|---|---|---|
| ||||
Posted in reply to Lionello Lunesu | Lionello Lunesu wrote: > What would be handy though is the expression appearing in the assert error message. Then you could write "int no_return_value; assert(no_return_value);" and the printed message would contain "no_return_value" as a hint. You mean like how the usual #define of assert works, in C ? #define assert(expr) \ ((void) ((expr) ? 0 : __assert (#expr, __FILE__, __LINE__))) Not that there any messages, but one could do something like: bool no_return_value = false; assert(no_return_value); To make such a "mock comment", on the line that it will point to ? I saw this first in std.loader: Didn't like it then, don't now ;-) { const int platform_not_discriminated = 0; static assert(platform_not_discriminated); } Might as well make it into a real comment in the code then: assert(0); // no return value I *think* that assert should take a boolean and a string, but I don't think it will ever be anything but an integer. Oh well, if it was good enough for C - why improve it... :-P --anders |
December 05, 2005 Re: Error: AssertError Failure | ||||
---|---|---|---|---|
| ||||
Posted in reply to Anders F Björklund | Anders F Björklund wrote:
> Tiago Gasiba wrote:
>
>>>>> Error: AssertError Failure test.d(8)
>>>>>
>>>>> Anyonw know why? Thanks! ;-)
>>>>
>>>>
>>>> You've defined main() to return an int, but you never return anything.
>>>> Instead of a compiler error, D makes a return-value-less function a
>>>> runtime
>>>> error. More than once I've wished that the error message would be a
>>>> little
>>>> more specific..
>>
>>
>> I agree! Something like "ERROR: no return value" would be much nicer!
>
>
> The compiler just inserts an "assert(0);" line,
> and assert doesn't allow for any such messages...
> e.g. assert(false,"no return at end of function");
>
> func.c(689):
> if (global.params.warnings)
> { printf("warning - ");
> error("no return at end of function");
> }
>
> if (global.params.useAssert &&
> !global.params.useInline)
> { /* Add an assert(0); where the missing return
> * should be.
> */
> e = new AssertExp(endloc, new IntegerExp(0, 0, Type::tint32));
> }
> else
> e = new HaltExp(endloc);
>
> Side note: in the above code you can see that if
> you use -inline, then you'll get a "halt" instead!
> Same if you use -release, which disables all asserts.
>
>
>
> This is an oft-requested D feature, that
> assert() is allowed to take messages too.
>
> You can do this in Java, for instance:
> http://java.sun.com/j2se/1.4.2/docs/guide/lang/assert.html
>
> But so far it has been rejected, for D...
>
>
> I think it's similar to "Access Violation",
> which isn't guarded especially for either.
>
> In Java, you would get a NullPointerException
> with the stack trace of the callers (catchable).
>
> In D, it's time to bring out the debugger...
I would very much prefer
*(cast(byte *)0)=0;
over
assert(0);
This would give a segmentation fault that the debugger would be able to catch and publish together with context (current stack). Even worse are runtime array index out of bounds error without even line number information...
/Oskar
|
December 05, 2005 Re: Error: AssertError Failure | ||||
---|---|---|---|---|
| ||||
Posted in reply to Oskar Linde | Oskar Linde wrote: > I would very much prefer > > *(cast(byte *)0)=0; > > over > > assert(0); > > This would give a segmentation fault that the debugger would be able to catch and publish together with context (current stack). Even worse are runtime array index out of bounds error without even line number information... -release should give you a "halt"/crash instead - but you can also redefine your "_d_assert", from: extern (C) static void _d_assert(char[] filename, uint line) { //printf("_d_assert(%s, %d)\n", cast(char *)filename, line); AssertError a = new AssertError(filename, line); //printf("assertion %p created\n", a); throw a; } From http://www.digitalmars.com/techtips/unittests.html --anders |
Copyright © 1999-2021 by the D Language Foundation