trying to decipher my first big program, which is a LISP interpreter, in that case. I am totally new to the world of understanding someone else's code, and it seems far more complex than coding oneself.
I can hardly produce a minimal version of my current difficulty, as my current difficulty resides in minimizing the existing code in order to better grasp it, and I encounter bugs almost at each modification I try.
The interpreter uses Current_Input and Current_Output globals to abstract reading and writing to and from files and widgets. I am just trying to make it write to stdout.
The relevant lines are :
Current_Output = alloc_objet(sizeof(Widget *));
objet_type(Current_Output) = OWIDGET;
Owidget(Current_Output) = Wtext;
Allocating an object (the uber-type), telling it its real type is "WIDGET", and assigning the Widget Wtext to it.
The type OFILE already exists, and has a macro Ofile similar to the Owidget macro, here are both :
#define Owidget(objet) (* ((output_widget) objet + JMP))
#define Ofile(objet) ((FILE *) objet + JMP)
I wanted to replace the three relevant line thus :
Current_Output = alloc_objet(sizeof(FILE *));
objet_type(Current_Output) = OFILE;
Ofile(Current_Output) = stdout;
which produces the following error :
error: lvalue required as left operand of assignment Ofile(Current_Output) = stdout;
This line :
printf("%d", Ofile(Current_Output));
Produces this warning :
warning: format ‘%d’ expects argument of type ‘int’, but argument 2 has type ‘FILE* {aka _IO_FILE*}’ [-Wformat=]
leading me to believe I have a FILE * on the left side of the bugging line, to which I want to assign stdout, another FILE *.
What is wrong here? Thank you!
FILE*
is a type, it doesn't have rvalueness / lvalueness.
You're passing ((FILE *) objet + JMP)
which is a temporary which is an rvalue.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With