The float i; line is a SNL statement, not a C statement. SNL doesn't provide a mechanism for variables to be statically initialized.
Taking a look at the generated C code for the working example might provide you some insight into what's happening 'under the hood'. On Sep 29, 2011, at 9:58 AM, Bradley Pietrzak wrote: Thanks again for the help. I have found another issue, though, and I sincerely apologize if it is yet another fundamental C error. Can anybody shed any light on why Program 1 shown below does work while Program 2 does not even successfully compile? I have highlighted the only differences between the two programs with "***************".
Program 1:
/* Sample Program */ program sncExample
option +r; /* reentrant */
float i; ***********
float pv; assign pv to "testioc:magnet{mag}";
%{
void helloWorld(SS_ID ssId, struct UserVar *pVar) {
pVar->i = 1; **************** printf("Hello World! You have just called a C function, and the variable i is %5.1f \n", pVar->i); }
}%
ss ss1 {
state one {
when() { %% helloWorld(ssId, pVar); pv = 1; pvPut(pv); sleep(1); } state two }
state two { when () { %% helloWorld(ssId, pVar);
pv = 2; pvPut(pv); sleep(1); } state one }
}
Program 2:
/* Sample Program */ program sncExample
option +r; /* reentrant */
float i = 1; ****************
float pv; assign pv to "testioc:magnet{mag}";
%{
void helloWorld(SS_ID ssId, struct UserVar *pVar) { printf("Hello World! You have just called a C function, and the variable i is %5.1f \n", pVar->i);
}
}%
ss ss1 {
state one { when() { %% helloWorld(ssId, pVar); pv = 1; pvPut(pv); sleep(1); } state two }
state two {
when () { %% helloWorld(ssId, pVar); pv = 2; pvPut(pv); sleep(1); } state one }
}
The error message displayed upon compiling program 2 is :
./../sncExample.stt: In function ‘helloWorld’: ./../sncExample.stt:15: error: ‘struct UserVar’ has no member named ‘i’ ./../sncExample.stt: In function ‘A_ss1_one’: ./../sncExample.stt:24: error: ‘struct UserVar’ has no member named ‘pv’
./../sncExample.stt:26: warning: implicit declaration of function ‘sleep’ ./../sncExample.stt: In function ‘A_ss1_two’: ./../sncExample.stt:33: error: ‘struct UserVar’ has no member named ‘pv’ ./../sncExample.stt: At top level:
./../sncExample.stt:50: error: ‘struct UserVar’ has no member named ‘pv’
Thanks everybody!
Brad Pietrzak
On Mon, Sep 26, 2011 at 6:02 PM, J. Lewis Muir <[email protected]> wrote:
On 9/26/11 4:39 PM, Bradley Pietrzak wrote:
> Thank you again for your responses. Unfortunately, I have encountered
> another problem, this time involving code that has been escaped to C. The
> new version of my program is shown below. Without the re-entrant option,
> the code runs perfectly fine. With the re-entrant option, however, I am met
> with several errors. The SNL user's manual says that the SNC automatically
> refers to variables in the struct UserVar by running the code " pVar->xxx",
> but that such references have to be handled manually for escaped C code. How
> do I handle such situations manually?
Hi, Brad.
In your example, you would need to do:
%% helloWorld(pVar->i);
Or, if you are wanting to do more things within your helloWorld
function, you could call it like this:
%% helloWorld(ssId, pVar);
with the function changed to:
void helloWorld(SS_ID ssId, struct UserVar *pVar) {
printf("Hello World! You have just called a C function, "
"and the variable i is %5.1f \n", pVar->i);
}
Lewis
|