Structs in C can have constructors?

0

I have the following structure within a program:

 struct STR00034ST{

     char C_O010XC14B, C_O020XC14B;
     short S_0010XI15C;
     float F_0010XI1D;

     STR00034ST (char _C_O010XC14B, char _C_O020XC14B,  short _S_0010XI15C, float _F_0010XI1D){

        C_O010XC14B=_C_O010XC14B;
        C_O020XC14B=_C_O020XC14B;
        S_0010XI15C=_S_0010XI15C; 
        F_0010XI1D=_F_0010XI1D;
    }
};

But whenever I compile it returns the following error: 'error: expected specifier-qualifier-list before' STR00034ST ''

I've been researching and realized that I only found examples of using constructors in struct within the C ++ language and not in C. So it's impossible to use constructors inside a struct in C?

    
asked by anonymous 19.02.2018 / 10:03

1 answer

2

You can not use C constructors, so you would have to create an auxiliary function that creates and initializes structs. In C99 there is also a technique called Compound Literal , which constructs an in-place structure. The syntax would be:

( type ) { initializer-list } ,

For example,

struct foo {int a; char b[2];} structure; .

    
19.02.2018 / 10:32