1

I have a struct defined inside capi_utils.h that looks like the following:

#ifndef _CAPI_UTILS_H_
# define _CAPI_UTILS_H_

...

struct ScalarVariable{
    char name[63];
    float value;
    uint8_T DataID;
    char type[50];
};

...
#endif

Inside of capi_utils.c I tried creating a variable to hold the struct like this

struct ScalarVariable sVariable;

Which only produces an error when I try setting a value inside the struct like this:

sVariable.name = paramName;

Error message is:

capi_utils.c:27: error: invalid use of undefined type `struct ScalarVariable'

What am I doing wrong?

EDIT 1:

I just had to include capi_utils.h. Didn't think I had to because I had understood source files and headers different for some reason.

EDIT 2:

To clarify, I even got errors when trying to set DataID, not only the array.

void GetValueFromAdress(const char_T*  paramName,
                     void*          paramAddress,
                     uint8_T        slDataID,
                     unsigned short isComplex,
                     uint_T*        actualDims,
                     uint_T         numDims,
                     real_T         slope,
                     real_T         bias) {

sVariable.DataID = slDataID;

}

Would produce error: invalid use of undefined type 'struct ScalarVariable'

11
  • did you include capi_utils.h inside capi_utils.c ^^' Commented Jun 25, 2018 at 14:17
  • Also, the name field is an array. So sVariable.name = paramName; is wrong. Commented Jun 25, 2018 at 14:18
  • What is the type of paramName ? Commented Jun 25, 2018 at 14:19
  • @Stargateur, Oh you have to do that? I thought they somehow were connected because it's a header for the source or something, heh.. Seems like it's working now though! Thanks :) Commented Jun 25, 2018 at 14:19
  • You can't assign arrays with =, simple as that. It has nothing to do with structs. Use strcpy. Commented Jun 25, 2018 at 14:21

1 Answer 1

1

In cape_utlis.c, you need to include the header file, like this:

#include cape_utlis.h

Moreover, change this:

sVariable.name = paramName;

to this:

strcpy(sVariable.name, paramName)

in order to copy the NULL-terminated string in C, you use the function strcpy, and not the assignment operator.

Sign up to request clarification or add additional context in comments.

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.