digitalmars.D - Error: Access Violation
- "Brian Gardner" <briangr friberg.us> Mar 23 2005
- "Regan Heath" <regan netwin.co.nz> Mar 23 2005
- Brian Gardner <Brian_member pathlink.com> Mar 24 2005
- "Regan Heath" <regan netwin.co.nz> Mar 25 2005
- =?ISO-8859-15?Q?Thomas_K=FChne?= Mar 24 2005
- "Walter" <newshound digitalmars.com> Apr 05 2005
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
Mar 23 2005
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
Mar 23 2005
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
Mar 24 2005
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
Mar 25 2005
-----BEGIN PGP SIGNED MESSAGE-----
Hash: SHA1
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
-----BEGIN PGP SIGNATURE-----
Version: GnuPG v1.4.0 (MingW32)
iD8DBQFCQ7bq3w+/yD4P9tIRAu66AJ47SC7gAsWS8WvgUHBHeX+xyEgQPACfWC0R
rBjJMWMONLVZ7f05AL4Pmu8=
=hqGj
-----END PGP SIGNATURE-----
Mar 24 2005
The trouble with both examples is the:
typedef u *u();
which is a circular reference. The compiler now issues a diagnostic.
Apr 05 2005









"Regan Heath" <regan netwin.co.nz> 