--- layout: fc_discuss_archives title: Message 9 from Frama-C-discuss on September 2011 ---
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

[Frama-c-discuss] slicing problem



Hi all
i have the following c code and i want to make slice just inside  
procedure calculate for array a[k] not for the whole program . pls can  
you tell me how can i do that.

  #include<stdio.h>

struct _list1
{
int data;
struct _list1 *next1;
};
typedef struct _list1 list1;

struct _reco {
int data;
list1 *right ;
struct _reco *next;
};
typedef struct _reco reco;

reco *p,*q, *p1,*p2;
long a[1000],a1[1000];

reco * makelist(int x)
{
  int i;
   p=NULL;
   p1=malloc(sizeof(reco));
   p1->data=NULL;
   p=p1;
   for(i=1;i<x;i++)
      {
       p2=malloc(sizeof(reco));
       p2->data=i;
       p1->next=p2;
       p2->next=NULL;
       p2->right=NULL;
       p1=p2;
     }
return p;
}

list1 * makelist2(int x)
{
   list1 *pw,*pw1,*pw2;
  int i;
   pw=NULL;
   pw1=malloc(sizeof(list1));
   pw1->data=NULL;
   pw=pw1;
   for(i=1;i<x;i++)
      {
       pw2=malloc(sizeof(list1));
       pw2->data=i;
       pw1->next1=pw2;
       pw2->next1=NULL;
       pw1=pw2;
     }
return pw;
}



calculate(reco *mp)
{
list1 *p11,*p21,*p31,*v;
   int i,i1,temp;
    long sum=0;
    long sum1=0;
   p11=mp->right->next1;
   int k=0;
   while (p11->next1!=NULL)
     {
       // printf(" the data %d\n",p11->data);
        if(p11->data <500)
         {
           for (i=1;i<=p11->data;i++)
            {
             sum=sum+sin(i);
             }
           //  printf(" the factorial %d\n",fact);
             a[k]=sum;
             k=k+1;
            }

       p11=p11->next1;
     }

  p21=mp->right->next1;
   int k2=0;
   while (p21->next1!=NULL)
     {
       // printf(" the data %d\n",p11->data);
        if(p21->data <500)
         {
           for (i1=1;i1<=p21->data;i1++)
            {
             sum1=sum1+cos(i1);
             }
           //  printf(" the factorial %d\n",fact);
             a1[k2]=sum1;
             k2=k2+1;
            }

       p21=p21->next1;
     }

}


int main()
{
   int x;
   x=100;
list1 *w;
   p=makelist(x);
   q=p;

   while(q!= NULL)
    {
      x=500;

      w=makelist2(x);
     q->right=w;
      q=q->next;
    }
int k1=0;
   while (p!= NULL) // main loop
    {
     calculate(p);
     p=p->next;
    }
}

many thanks
esraa