0

I have a struct and a function, which returns a pointer to the struct it read:

typedef struct cal_t {
    float xm; 
    float ym; 
    float xn; 
    float yn; 
} cal_t;


struct cal_t *lld_tpReadCalibration(void);

Somewhere else, I do have an instance of that struct:

struct cal_t cal;

Now I need to assign tha values of that instance of the struct to the values of the struct I get the pointer returned of. So what I want is that cal.xm is the same value as cal->xm in inside lld_tpReadCalibration(). Symbolicly:

struct cal_t cal;

cal = lld_tpReadCalibration();

But this dosen't work, of course:

error: incompatible types when assigning to type 'volatile struct cal_t' from type 'struct cal_t *'

How can I make this work the way I want it?

Thanks for your help.

2 Answers 2

2

You need to dereference the pointer somehow. You're getting back a pointer from the function, so you're looking for either a * operator or ->, which is of course a synonym for a * with .

You define cal as a struct cal_t, the function returns a pointer to cal_t. so you need to dereference the pointer.

cal = *lld_tpReadCalibration();
Sign up to request clarification or add additional context in comments.

Comments

1

The function return value is struct cal_t *, which is pointer type.

So,you should assign the return value to variable that the type is a struct cal_t *.

For example,

struct cal_t *cal_ptr;

cal_ptr = lld_tpReadCalibration();

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.