Hi,

I have a structure defined in my header file as follows:

struct TestInformation
{
    int TestPointer;				// pointer to the selected test
    long TestPointerValue;			// the value contained within the pointer
    long TestSize;				// the size of a test
    char *TestText;				// the text contained within a test
};

In my source file, I have a function in which I want to declare an array of those structures, to be passed to another function to be filled and returned:

struct TestInformation *BoardTests[0x100];	
	
    // Get the file into an internal structure
    iError = TSL1_LoadTSLInternal(TSL_TEMP_FILE, BoardTests, iGlbNumTests);
...
...
...
    return iError;

Now, my declaration of TSL1_LoadTSLInternal looks like this:

int TSL1_LoadTSLInternal (char *filename, struct TestInformation *BoardTests[0x100], int iGlbNumTests)

So, in that function i'd like to be able to index into the structure:

BoardTests[i].TestPointer

but I am getting a compilation error:
C:\Projects\uMaster3xxxC++\IntelDriver\TSL1\TSL1.cpp(273) : error C2228: left of '.TestPointer' must have class/struct/union type

Can anyone help? I know this is possible because I've done something similar with a char array, I just can't seem to get this one right.
Any help greatly appreciated.

Recommended Answers

All 6 Replies

isn't BoardTests an array full of TestInformation pointers? if so, you should refer to a single unit in the array as

BoardTests->TestPointer
or
*(BoardTests).TestPointer

Hi, thanks, those work for compilation errors, but now debugging an access violation is occurring when I get to the first reference to it.
Any ideas?

I think you should reserve the memory for the array dynamically with the command new. That way there should be no memory related problems with the array. Just remember to delete it later on.

I cannot use the new command in the project. We are restricted to using ansi c functions. Is there an alternative? I think the access violation is occurring because of the array being uninitialized?

I have resolved this as follows:

// create the array and a pointer to it
TestInformation BoardTests[0x100];
TestInformation *pBoardTests = BoardTests;


// now pass the pointer as a parameter:
iError = TSL1_LoadTSLInternal(TSL_TEMP_FILE, &pBoardTests, iGlbNumTests);

//Access it in TSL1_LoadTSLInternal:

BoardTests[i]->TestPointer = currentTestLocation;

But trying to index any further than i = 0 causes another access violation.

Now I have resolved:

TestInformation BoardTests[0x100];
TestInformation *pBoardTests[0x100];
for (int i = 0; i < 256; i++)
    pBoardTests[i] = &BoardTests[i];

iError = TSL1_LoadTSLInternal(TSL_TEMP_FILE, pBoardTests, iGlbNumTests);

...
...
...
int TSL1_LoadTSLInternal (char *filename, TestInformation *BoardTests[], int iGlbNumTests)
...
...
...
BoardTests[i]->TestPointer = currentTestLocation;

Now returning to the calling function, I have my original array fully populated.

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.