Is FILE * not an lvalue?

trying to decrypt my first big program, which is a LISP interpreter, in this case. I am completely new to the world of understanding the code of another, and it seems much more complex than the encoding itself.

I can hardly create a minimal version of my current difficulty, since my current difficulty is to minimize the existing code in order to better understand it, and I encounter errors in almost every modification that I try to execute.

The interpreter uses the global variables Current_Input and Current_Output to abstractly read and write files and widgets from and to them. I'm just trying to get it to write to stdout.

Matching lines:

Current_Output = alloc_objet(sizeof(Widget *));
objet_type(Current_Output) = OWIDGET;
Owidget(Current_Output) = Wtext;

Select an object (uber type), telling it that its real type is "WIDGET", and assign it a Widget Wtext.

The OFILE type already exists and has an Ofile macro file, similar to the Owidget macro, that's all:

#define Owidget(objet) (* ((output_widget) objet + JMP))
#define Ofile(objet) ((FILE *) objet + JMP)

I wanted to replace the three matching lines with this:

Current_Output = alloc_objet(sizeof(FILE *));
objet_type(Current_Output) = OFILE;
Ofile(Current_Output) = stdout;

which causes the following error:

error: lvalue required as left operand of assignment Ofile(Current_Output) = stdout;

This line:

printf("%d", Ofile(Current_Output));

Throws this warning:

warning: format β€˜%d’ expects argument of type β€˜int’, but argument 2 has type β€˜FILE* {aka _IO_FILE*}’ [-Wformat=]

making me believe that I have a FILE * on the left side of the listening line to which I want to assign stdout to another FILE *.

What is wrong here? Thanks!

+4
source share
1 answer

FILE* - this is a type, it does not have a difference / weight.

You pass ((FILE *) objet + JMP), which is a temporary rvalue value.

+12
source

All Articles