03-18-2014 08:33 AM
Hopefully this is simple. It is confusing.
I am trying to pass a structure address to a function. Need to because the code in the function needs to operate on the contents of several structures. The very simplified version of this code looks like this:
// Structure declaration
struct xxxStruct {
int aaa;
double bbb;
c har ccc;
} AAA, BBB, CCC, DDD;
// Function Declaration
void ProcessStuff ( struct xxxStruct * passedStruct);
// Function source
void ProcessStuff ( struct xxxStruct * passedStruct)
{
double tempDbl;
tempDbl = passedStruct->bbb + (double)passedStruct->aaa;
}
// Function called
main()
{
ProcessStuff(&AAA);
etc, etc.
}
This generates compile time errors like this:
208, 34 warning: incompatible pointer types passing 'struct passedStruct*' to parameter of type 'struct passedStruct*'
Besides the fact that thiserror message is meaningless, what am I doing wrong?
CVI2013SP1 on Win7
03-18-2014 09:01 AM
Hello,
When I try to compile this code in CVI 2012 (on Win 7), there's no problem...
Are you sure that the full version of this code corresponds to this simplified version ? Maybe anybody else will be able to reproduce the problem with CVI 2013 ?
03-18-2014 10:37 AM
Yes, what I sent was too simple. I compiled it, elaborated on it, and it worked fine.
After investigating, elaborating on the simple program even more, recreating it in the architecture of my large applications, with multiple .h files for variables, defines, and declarations, I learned something important about this compiler:
For this particular method, that is passing a structure address to a function, the structure has to be defined before the function prototype is declared. If it is the other way around, you get that nonsense error. I had not run across that kind of issue before.
Problem solved.
03-19-2014 04:21 AM
From the point of view of my coding habits, I would not type struct variable names AAA, BBB, CCC, DDD in the struct definition.
Instead, I would do it like this:
In the header file:
// types.h
// Structure declaration
typedef struct _xxxStruct {
int aaa;
double bbb;
char ccc;
} xxxStruct;
Then, in the source file:
// Function called
#include "types.h"
// Function Declaration
void ProcessStuff (xxxStruct * passedStruct);
// Function source
void ProcessStuff (xxxStruct * passedStruct)
{
double tempDbl;
tempDbl = passedStruct->bbb + (double)passedStruct->aaa;
}
main()
{
xxxStruct AAA, BBB, CCC, DDD;
ProcessStuff(&AAA);
//etc, etc.
}