Modifying through pointer-to-const

From: Dave (better_cs_now_at_yahoo.com)
Date: 04/19/04


Date: Mon, 19 Apr 2004 13:52:29 -0700

Hello all,

In the code below, I am able to modify data through the pointer-to-const
DynGapRec parameter. The last two lines show this. I didn't want to create
a huge message, so there's a *lot* of context that's missing. If this is
not enough to work with, I will, of course, understand. My question is: Is
there *any* circumstance where this should be legal, or do I definitely have
a compiler bug (VC++ 7.1)?

Thanks,
Dave

void CInstrProcEngine::AggregateDynamicGapRecords(const CAccount* iAcct,
                                      const SingleInstr* pInstr,
                                      const int* evPoints,
                                      const CGapInt* pGap,
                                      const DynGap* DynGapRec,
                                      CDate forecastDate,
                                      int RateType,
                                      int startPd,
                                      int endPd)
{
   if (pGap->i_NumGapIntervals <= 0)
      return;

   int index = 0;
   int NumEvPts = 0;
   int currentEvPt = 0;
   double nMoROBal;

   double* SaleAmt = pInstr->SaleAmt;
   double SaleAdjustment[MAX_PERIOD + 2] = {0.0};

   while (currentEvPt < LAST_PERIOD && (index < DynGapRec->mTotPds))
   {
      if (evPoints[currentEvPt])
      {
         BOOL reprFlag = FALSE;

         NumEvPts++;

         CDate tempDate;
         tempDate = forecastDate;
         tempDate.AddMonths(currentEvPt);

         SaleAmt = pInstr->SaleAmt;
         if(!pInstr->SrvcFlag)
         {
            double notUsed = 0;

            CalcSalesAdjustment(
                                  currentEvPt,
                                  endPd + 1,
                                  pInstr->UnModContractualRo,
                                  pInstr->OvPrepayments,
                                  pInstr->EvInterestCashflow,
                                  pInstr->SaleAmt,
                                  forecastDate,
                                  SaleAdjustment,
                                  notUsed,
                                  false
                               );

            SaleAmt = SaleAdjustment;
         }

         // calculate gap buckets
         for (int gapRecCnt=0; gapRecCnt < pGap->i_NumGapIntervals;
gapRecCnt++)
         {
            DynGaRec->MvPeriod[index] = currentEvPt; // ILLEGAL!!!
            DynGapRec->GapInteval[index] = pGap->i_GapEndMt[gapRecCnt]; //
ILLEGAL!!!

. . .
. . .
. . .
. . .
}