开发者

How to pass a struct to a function in a yacc file?

开发者 https://www.devze.com 2022-12-13 18:51 出处:网络
I have this in my yacc file. var_declaration : type_specifier ID \';\' {$2->args = \"\"; $2->value = 0; $2->arraysize = 0; $2->type = \"variable\";}

I have this in my yacc file.

var_declaration : type_specifier ID ';' {$2->args = ""; $2->value = 0; $2->arraysize = 0; $2->type = "variable";}

Everything above works.

I want to add this to it.

fn($2);

From inside the function, I want to do stuff like this.

 fn(struct symtab sp)
    {
开发者_如何学JAVA    sp->value = 0;
    }

But when I try to compile the program I get this error:

error: invalid type argument of ‘->’ (have ‘struct symtab')


I guess your function should be

fn(struct symtab* sp)

instead of

fn(struct symtab sp)

and by the way, as $2 is a union I don't think that

$2->args = ""; $2->value = 0; $2->arraysize = 0; 

is correct. And

$2->type = "variable";

is not valid.

0

精彩评论

暂无评论...
验证码 换一张
取 消