my errors about use of parameter ' ***** 'outside function body

Hi friends,
Running the following program results in these errors:
1
2
3
4
5
6
  line 1 error: use of parameter ‘arraysize’ outside function body.
  line 1 error: expected ‘)’ before ‘,’ token.
  line 1 error: expected unqualified-id before ‘int’.
  line 134 error: use of parameter ‘arraysize’ outside function body.
  line 134 error: expected ‘)’ before ‘,’ token.
  line 134 error: expected unqualified-id before ‘int’.

Here is the program:
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
  int findvalue (const int arraysize, int myarray[arraysize], int value);
double Pd_kinema(double theta_lab,double phi_lab,int id);


TPaveText *pt[21];

const int arraysize=150;
int myarray[arraysize];

TCutG *cutEFW;


void Balldets_raw ()
{
TStopwatch timer;
timer.Start();

char rNosNo[250];
sprintf(rNosNo,"r%ds%d",ringNo,struNo);

TPostScript *ps = new TPostScript(psfile,111);
ps->Range(19,24);   //set x,y of printed page in cm //

gROOT->Macro("openntuple.cxx");
gROOT->Macro("ElasticKinemaGraphs.cxx");

gStyle->SetOptStat(10);

TCanvas *c1 = new TCanvas("c1","BINA Canvas 1");  c1->SetFillColor(10);  c1->Size(21,29);  c1->Divide(2,5);
c1->SetRightMargin(0); c1->SetLeftMargin(0); c1->SetTopMargin(0); c1->SetBottomMargin(0); 

TLegend *legend; 

char name[50][250], name1[50][250], name2[50][250];

Double_t BSE[arraysize], Bnr[arraysize], Btheta[arraysize], Bphi[arraysize];
Double_t MWPCphi, MWPCtheta, WDdE, WUdE, WLE, WRE, WLdet, WRdet, WDdet, WUdet, MWPCX, MWPCY, EFW;
Double_t T1, T2, pureT1;
Double_t EventType, ballhits;

int counter=-1, maxBSE, index_of_maxBSE, Det_of_maxBSE, det, size, Centtheta, Lowtheta, l, m;

elasticchain->SetBranchAddress("b3",Bnr);
elasticchain->SetBranchAddress("b5",BSE);
elasticchain->SetBranchAddress("b6",Btheta);
elasticchain->SetBranchAddress("b7",Bphi);

TBranch *b2 = elasticchain->GetBranch("b2");
TLeaf *ballhitsleaf = b2->GetLeaf("ballhits");
TLeaf *MWPCphileaf = b2->GetLeaf("MWPCphi");
TLeaf *MWPCthetaleaf = b2->GetLeaf("MWPCtheta");
TLeaf *WDdEleaf = b2->GetLeaf("WDdE");
TLeaf *WUdEleaf = b2->GetLeaf("WUdE");
TLeaf *WLEleaf = b2->GetLeaf("WLE");
TLeaf *WREleaf = b2->GetLeaf("WRE");
TLeaf *WLdetleaf = b2->GetLeaf("WLdet");
TLeaf *WRdetleaf = b2->GetLeaf("WRdet");
TLeaf *WDdetleaf = b2->GetLeaf("WDdet");
TLeaf *WUdetleaf = b2->GetLeaf("WUdet");
TLeaf *MWPCXleaf = b2->GetLeaf("MWPCX");
TLeaf *MWPCYleaf = b2->GetLeaf("MWPCY");
TLeaf *EFWleaf = b2->GetLeaf("EFW");
TLeaf *T1leaf = b2->GetLeaf("T1");
TLeaf *T2leaf = b2->GetLeaf("T2");
TLeaf *pureT1leaf = b2->GetLeaf("pureT1");
TLeaf *EventTypeleaf = b2->GetLeaf("EventType");

/************************************* loop over events  *************************************/

for (Long64_t jentry=Firstentry;  jentry<Nentries;  jentry++)
    { 
      counter++;
      fprintf(stdout,"\rEvent No=%2.2e\t",counter); 
      elasticchain->GetEntry(jentry);
      ballhits=ballhitsleaf->GetValue();
      MWPCphi=MWPCphileaf->GetValue();
      MWPCtheta=MWPCthetaleaf->GetValue();
      WDdE=WDdEleaf->GetValue();
      WUdE=WUdEleaf->GetValue();
      WLE=WLEleaf->GetValue();
      WRE=WREleaf->GetValue();
      WLdet=WLdetleaf->GetValue();
      WRdet=WRdetleaf->GetValue();
      WDdet=WDdetleaf->GetValue();
      WUdet=WUdetleaf->GetValue();
      MWPCX=MWPCXleaf->GetValue();
      MWPCY=MWPCYleaf->GetValue();
      EFW=EFWleaf->GetValue();
      T1=T1leaf->GetValue();
      T2=T2leaf->GetValue();
      pureT1=pureT1leaf->GetValue();
      EventType=EventTypeleaf->GetValue();
      index_of_maxBSE=0;

      if ( EventType==1 )
        {
         for (i=1; i<=ballhits; i=i+1)  
            {
              det= (int)Bnr[i];
              if (findvalue(rsSize,rsArray,det)==1 )
                {
                  BSEall[det]->Fill(BSE[i]);
                 // mintheta=Pd_kinema(Btheta[i]+10,30,5);
                  //maxtheta=Pd_kinema(Btheta[i]-10,30,5);
                  //fprintf(stdout,"\nmintheta=%d , maxtheta=%d\n",mintheta,maxtheta);
                  if ( MWPCtheta>mintheta && cutEFW->IsInside(MWPCtheta,EFW) )  
                    { 
                      //BSEthcut[det]->Fill(BSE[i]);
                      BSEfithEcut[det]->Fill(BSE[i]);
                      //BallMult[det]->Fill(ballhits);
                      
                    }
                }
            }
        }
    }
/************************************ end of loop over events *********************************/

fprintf(stdout,"\nevents=%d\n",counter+1);
     

elasticchain->ResetBranchAddresses();
ps->Close();

timer.Stop();
Double_t rtime = timer.RealTime();  
Double_t ctime = timer.CpuTime();
printf("RealTime=%d min, CpuTime=%d min",rtime/60.,ctime/60.);
fprintf(stdout,"\nAll histograms are saved in %s\n",psfile);
}
/************************************************ end of main *********************************************************/

/* Check if a particular value exist in the array */
int findvalue (const int arraysize, int myarray[arraysize], int value) 
{
  int * p;
  p = std::find (myarray, myarray+arraysize, value);
  if (p != myarray+arraysize) return 1;
  else  return 0;
}

If anyone can explain why this is happening and how I can get this to work it would be very appreciated. Thanks.
Last edited on
In line 1 of your program you are trying t use a variable that has not yet been declared.
int findvalue (const int arraysize, int myarray[arraysize], int value);
You can solve the problem by just removing arraysize from inside the braces since it's not needed:

int findvalue (const int arraysize, int myarray[], int value);

Why are you passing arraysize into this function? You have declared a global variable with this name, a few lines later. Either move the variable declaration into the calling function or remove the parameter and just use the global variable.

Thanks.
removing arraysize from inside the braces result in these errors:
1
2
 line 100 invalid conversion from ‘int’ to ‘int*’ [-fpermissive]
line 1 initializing argument 2 of ‘int findvalue(int, int*, int)’ [-fpermissive]
Please show your current code. Also it would be easier to see the actual problem if you posted a small complete program. A program that has all the parts that don't relate to the actual problem you're trying to solve removed.
Something like:
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
#include <iostream>
#include <algorithm>

bool findvalue(const int arraysize, int myarray[], int value);
double Pd_kinema(double theta_lab, double phi_lab, int id);


const int arraySize = 150;

int main()
{
    int rsSize = 110;
    int rsArray[arraySize];
    int counter = 1;
    // Populate the array.
    for(auto& itr : rsArray)
        itr = counter++;

    // Search the first rsSize elements for 120
    std::cout << std::boolalpha << findvalue(rsSize, rsArray, 120) << std::endl;
    // Search the entire array for 120.
    std::cout << findvalue(arraySize, rsArray, 120) << std::endl;

}
/************************************************ end of main *********************************************************/

/* Check if a particular value exist in the array */
bool findvalue(const int arraysize, int myarray[], int value)
{
    int * p;
    p = std::find(myarray, myarray + arraysize, value);
    if(p == myarray + arraysize)
        return false;
    return true;
}


And is this a C or C++ program?

If C++ why are you using arrays instead of std::vector, and printf() instead of the C++ streams?

Why all the global variables?
Topic archived. No new replies allowed.