Thread overview | ||||||||
---|---|---|---|---|---|---|---|---|
|
March 23, 2005 Error: Access Violation | ||||
---|---|---|---|---|
| ||||
Why the program produced from the following code enters loop which ends with the message: "Error: Access Violation"? import std.c.stdio; typedef u *u(); u *s() { static int x = 0; printf("%d\n", x++); return s; } int main(){ s(); return 0; } For the below code the compiler (v0.119) reports "Internal error: ..\ztc\cgcod.c 1445": import std.c.stdio; typedef u *u(); u s() { static int x = 0; printf("%d\n", x++); return s; } int main(){ s(); return 0; } Thank you, Brian |
March 24, 2005 Re: Error: Access Violation | ||||
---|---|---|---|---|
| ||||
Posted in reply to Brian Gardner | On Wed, 23 Mar 2005 20:00:36 +0200, Brian Gardner <briangr@friberg.us> wrote: > Why the program produced from the following code enters loop which ends with > the message: "Error: Access Violation"? > > import std.c.stdio; > > typedef u *u(); > > u *s() > { > static int x = 0; > printf("%d\n", x++); > return s; > } > > int main(){ > s(); > return 0; > } My guess is that the "return s;" statement in the "s" function calls the "s" function again. > For the below code the compiler (v0.119) reports "Internal error: > ..\ztc\cgcod.c 1445": > > import std.c.stdio; > > typedef u *u(); > > u s() > { > static int x = 0; > printf("%d\n", x++); > return s; > } > > int main(){ > s(); > return 0; > } This is a bug with DMD. I have cross-posted my reply to the digitalmars.d.bugs group. Regan |
March 24, 2005 Re: Error: Access Violation | ||||
---|---|---|---|---|
| ||||
Posted in reply to Regan Heath | In article <opsn4csyii23k2f5@nrage.netwin.co.nz>, Regan Heath says... > >On Wed, 23 Mar 2005 20:00:36 +0200, Brian Gardner <briangr@friberg.us> wrote: >> Why the program produced from the following code enters loop which ends >> with >> the message: "Error: Access Violation"? >> >> import std.c.stdio; >> >> typedef u *u(); >> >> u *s() >> { >> static int x = 0; >> printf("%d\n", x++); >> return s; >> } >> >> int main(){ >> s(); >> return 0; >> } > >My guess is that the "return s;" statement in the "s" function calls the "s" function again. Isn't s (in "return s;") a pointer to function according to D? If not, how to obtain a pointer to function s without calling s? Thanks, Brian |
March 25, 2005 Re: Error: Access Violation | ||||
---|---|---|---|---|
| ||||
Posted in reply to Regan Heath Attachments: | Regan Heath wrote: | On Wed, 23 Mar 2005 20:00:36 +0200, Brian Gardner <briangr@friberg.us> | wrote: <snip> |> For the below code the compiler (v0.119) reports "Internal error: |> ..\ztc/cgcod.c 1445": |> |> import std.c.stdio; |> |> typedef u *u(); |> |> u s() |> { |> static int x = 0; |> printf("%d\n", x++); |> return s; |> } |> |> int main(){ |> s(); |> return 0; |> } | | | This is a bug with DMD. | | I have cross-posted my reply to the digitalmars.d.bugs group. Added to DStress as http://dstress.kuehne.cn/nocompile/bug_cgcod_1445_A.d http://dstress.kuehne.cn/nocompile/bug_cgcod_1445_B.d Thomas |
March 25, 2005 Re: Error: Access Violation | ||||
---|---|---|---|---|
| ||||
Posted in reply to Brian Gardner | On Thu, 24 Mar 2005 13:55:07 +0000 (UTC), Brian Gardner <Brian_member@pathlink.com> wrote: > In article <opsn4csyii23k2f5@nrage.netwin.co.nz>, Regan Heath says... >> >> On Wed, 23 Mar 2005 20:00:36 +0200, Brian Gardner <briangr@friberg.us> >> wrote: >>> Why the program produced from the following code enters loop which ends >>> with >>> the message: "Error: Access Violation"? >>> >>> import std.c.stdio; >>> >>> typedef u *u(); >>> >>> u *s() >>> { >>> static int x = 0; >>> printf("%d\n", x++); >>> return s; >>> } >>> >>> int main(){ >>> s(); >>> return 0; >>> } >> >> My guess is that the "return s;" statement in the "s" function calls the >> "s" function again. > > Isn't s (in "return s;") a pointer to function according to D? > If not, how to obtain a pointer to function s without calling s? http://www.digitalmars.com/d/function.html#closures import std.stdio; typedef fn function(int) fn; fn foo(int i){ writefln("foo called (",i,")"); return &foo; } void main() { fn p = foo(1); p(2); } Regan |
April 05, 2005 Re: Error: Access Violation | ||||
---|---|---|---|---|
| ||||
Posted in reply to Regan Heath | The trouble with both examples is the: typedef u *u(); which is a circular reference. The compiler now issues a diagnostic. |
Copyright © 1999-2021 by the D Language Foundation