I have a dynamic array which will be updated from a different test system. I am havign hard time with syntax. Can someone please help me here?

Here is where I declare my vector

void TestSystem::Drive(U32 RunMode, U32 Options)
{ //U32 is unsigned 32 bit

  U32 condition;
  U32 i;
  U8 k;
  vector<U32> badDriveList(1,0);//initial size of vector is 1 and value is 0
  int *badDrivePointer[&badDriveList];

  bool driveStatus = testSystems[k]->DriveCheck(badDrivePointer);//should this be &badDrivePointer? 
// left side to "->" is correct. After that i am not sure  
}

Here is where I update my vector.

int TestSystem::DriveCheck(int *badDriveList)
{
  U32 condition;
  U32 i= 10;
  U32 j = 0;

  for(j;j<i;j++)
  {
  badDriveList[j] = (*i)->shelf;//right hand side of this is working when tested with complete code base 
  //I am not sure how to write values in to badDriveList vector using pointers
  }
}

here is part of my .h file

int recoverDriveCheck(int *);

Please help me out to get this thing right.

Recommended Answers

All 5 Replies

First, your declaration of badDrivePointer should probably be a pointer to a U32 object since that is what the vector is carrying, not ints. Additionally, according to your comments, a U32 is an unsigned type whereas an int is a signed type. Unless U32 is an inaccurately-named typedef for int, this would generally produce a compiler error about incompatible pointer types.

Second, if you want the address of a vector element, you need to select the element, then get the reference to the returned object U32 badDrivePointer = &(badDriveList[listIndex]);

You define badDriveList in one function and expect to be able to use it in another. That won't work, period. As you've written your code, badDriveList is a local variable in TestSystem::Drive, and will be destroyed as soon as TestSystem::Drive exits.

What you probably need to do is to make badDriveList a data member of TestSystem. Until you do that, or something like it, there's little point in talking about other problems.

You define badDriveList in one function and expect to be able to use it in another. That won't work, period. As you've written your code, badDriveList is a local variable in TestSystem::Drive, and will be destroyed as soon as TestSystem::Drive exits.

What you probably need to do is to make badDriveList a data member of TestSystem. Until you do that, or something like it, there's little point in talking about other problems.

I think you are correct that there are some logic and intent errors, and I agree that badDriveList would be better as a member of TestSystem instead of local to Drive. However,

void TestSystem::Drive(U32 RunMode, U32 Options)
{ //U32 is unsigned 32 bit
 
  U32 condition;
  U32 i;
  U8 k;
  vector<U32> badDriveList(1,0);//initial size of vector is 1 and value is 0
  int *badDrivePointer[&badDriveList];
 
  bool driveStatus = testSystems[k]->DriveCheck(badDrivePointer);//should this be &badDrivePointer? 
// left side to "->" is correct. After that i am not sure  
}

if you read the code properly, and ignore the syntax errors, you can see that they call DriveCheck from Drive. Since they are (attempting) sending a pointer to DriveCheck it should be fine because badDriveList isn't destroyed until Drive ends, which it hasn't. It's no different than creating an object in main() and sending a pointer to it to a sub-function; both functions just happen to be members of TestSystem.

That's true if the only place DriveCheck is called is from Drive--but we don't know that for sure.

That's true if the only place DriveCheck is called is from Drive--but we don't know that for sure.

First of all, I really appreciate help here form both of you.

I do see why it would be nice to be able to call driveCheck from out side of drive. But as of right now, I dont think I will need to call driveCheck from any where else other than while I am in drive.

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.