Thread overview
Error: Access Violation
Mar 23, 2005
Brian Gardner
Mar 24, 2005
Regan Heath
Mar 24, 2005
Brian Gardner
Mar 25, 2005
Regan Heath
Mar 25, 2005
Thomas Kühne
Apr 05, 2005
Walter
March 23, 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


March 24, 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

March 24, 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


March 25, 2005
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
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
The trouble with both examples is the:

    typedef u *u();

which is a circular reference. The compiler now issues a diagnostic.