Va_List <Bad Ptr> ??

So I am getting the error that va_list produces a 0xCCCCCCCC bad ptr. I know that it means that something is not being initialized right, or perhaps that its pointing off into space, but I don't see what I am doing to cause it so.


Also, I noticed that I am not placing the first argument in the function call to memory. Why so?

Also, I seem to be mixing up the sizes of my doubles and ints. Are my declarations correct?

Here is the code:

Main:

HERG HERG1a;

HERG1a.SetStateProbabilities(1,0,0,0,0);

Class:

double *StateProbabilities;

void SetNumberOfStates()
{this->StateProbabilities=new double[(this->NumberOfStates)];};

void SetStateProbabilities(double state1 ...);

Implementation File:

void IonChannel::SetStateProbabilities(double state1 ...)
{

va_list states;
this->NumberOfStates=sizeof(va_list);
this->SetNumberOfStates();
va_start(states,state1);

for (register int i=0; i <= sizeof(va_list); i++){

this->StateProbabilities[i] = va_arg(states, double);

}

va_end(states);
}

Any ideas?
Last edited on
sizeof(va_list)

What do you expect to happen? Do you expect to get the number of parameters passed to the function from this? That's not how variable argument lists work. The first parameter should be an unsigned long that contains the number of parameters passed to the function. This is the only way the function will know how many parameters were passed!
1
2
3
4
5
6
7
8
9
int add(unsigned long count, ...)
{
  va_list args;
  va_start(args, count);
  for(; count > 0; --count)
  {
    //Code here
  }
}
Topic archived. No new replies allowed.