/* Copyright (c) 2001-2009 by SoftIntegration, Inc. All Rights Reserved */
#include "expvar.h"

void changeCVar() {
  void *fptr;

  fptr = dlsym(_ChExpvar_handle , "changeCVar_chdl");
  if(fptr == NULL) {
     printf("Error: %s(): dlsym(): %s\n", __func__, dlerror());
     return;
  }

  /* Pass the address of retval to C space */
  dlrunfun(fptr, NULL, NULL);
  return;
}

int main() {
  int i;
  printf("Original values of i1 and i2 in Ch are %d and %d\n", i1, i2);
  changeCVar(); /* change variables in C space */
  printf("After calling changeCVar(), i1 and i2 are %d and %d\n", i1, i2);
  for(i=0; i<10; i++) {
    printf("a[%d] = %d\n", i, a[i]);
  }
  return 0;
}

/*** Result from excuting this program
The variables in the C space are 100 and 200
Original values of i1 and i2 in Ch are 100 and 200
The variables in the C space are 100 and 400
After calling changeCVar(), i1 and i2 are 100 and 400
a[0] = 1
a[1] = 2
a[2] = 3
a[3] = 300
a[4] = 5
a[5] = 6
a[6] = 7
a[7] = 8
a[8] = 9
a[9] = 10
***/
