PAT Forum
Would you like to react to this message? Create an account in a few clicks or log in to continue.

Can external static method modify the global variable defined in CSP#?

2 posters

Go down

Can external static method modify the global variable defined in CSP#? Empty Can external static method modify the global variable defined in CSP#?

Post  alex2ren Sun Jan 20, 2013 2:37 pm

I write the following code in CSP#.
Code:
#import "PAT.Lib.List";
#import "Mylib";
var g = 0;
P = a{call(inc, g);} ->  b{call(inc, g);} -> c{call(inc, g);} -> d{call(inc, g);} -> Skip;

The "Mylib.cs" goes as follows
Code:
using System;
using System.Collections.Generic;
using System.Text;
//the namespace must be PAT.Lib, the class and method names can be arbitrary
namespace PAT.Lib
{
    public class NewLib
    {
         public static int inc(ref int v)
        {
              v = v+1;
              return v;
        }
    }
}

Everything works fine except the fact that inc cannot actually modify the value of g. Can external static method modify the global variable defined in CSP#? Thanks.

alex2ren

Posts : 6
Join date : 2012-12-03

Back to top Go down

Can external static method modify the global variable defined in CSP#? Empty Re: Can external static method modify the global variable defined in CSP#?

Post  pat team Fri Jan 25, 2013 12:22 am

The primitive value (like int, bool) passed into the C# call is by value so even when you put ref in the method, it will not help. One way to solve this problem is to just do this: g = call(inc, g)

if the value passed in is an object, the update will be shown


alex2ren wrote:I write the following code in CSP#.
Code:
#import "PAT.Lib.List";
#import "Mylib";
var g = 0;
P = a{call(inc, g);} ->  b{call(inc, g);} -> c{call(inc, g);} -> d{call(inc, g);} -> Skip;

The "Mylib.cs" goes as follows
Code:
using System;
using System.Collections.Generic;
using System.Text;
//the namespace must be PAT.Lib, the class and method names can be arbitrary
namespace PAT.Lib
{
    public class NewLib
    {
         public static int inc(ref int v)
        {
              v = v+1;
              return v;
        }
    }
}

Everything works fine except the fact that inc cannot actually modify the value of g. Can external static method modify the global variable defined in CSP#? Thanks.

pat team
Admin

Posts : 17
Join date : 2010-02-15

http://www.comp.nus.edu.sg/~pat/

Back to top Go down

Back to top

- Similar topics

 
Permissions in this forum:
You cannot reply to topics in this forum