----- Begin Included Message -----
>Using g++ 2.7.2 under HPUX 9.05, I encountered scoping errors in six
>channel access service layer routines.
>File Method
---- -------
>caChannel.cc ::addMonitorObj
::removeMonitorObj
>caRequestObject.cc ::setValueCbk (two places)
::convertData
>caService.cc ::addReadFd
::removeReadFd
>The errors were all of the same form, illustrated here by the instance
>in caService::addReadFd():
>caService::addReadFd (int fd)
>{
> if (numFds_){
> int *newfds = new int[numFds_ + 1];
> for (int i =0; i < numFds_; i++)
> newfds[i] = fds_[i];
> delete []fds_;
> newfds[i] = fd;
><snip>
>While the compiler only generated warnings, the resultant program
>crashed with a Bus Error within caService::removeReadFd() during
>process exit handling - presumably due to garbage values with the
>newfds[] array.
>Declaring the loop index variables at the start of each method
>corrects the problem.
>Aloha,
> Peregrine
Make sure to use option -fno-for-scope in gcc (g++) which enables one
to do the following:
for (int i = 0; i < 100; i++)
dosomething;
with valid i after the loop. Otherwise the index i will be a unpredicated value.
--Jie Chen