print values of a struct without knowing the slot names

R

RolfK

Guest
Dear ALL,

I need to understand how I can print out a struct.
Assume ebb1 is an existing struct with values from which I do not know
its slot names.

Here is my (not working ) attempt.

Any idea how to make it running ?

foreach( (slot value) ebb1->?
printf("%s\n" slot))
/* The statement below can not work as slot is not treated as a
variable.
How to make it right ? */
printf("%L\n" ebb1->slot);
)
 
Here is my (not working ) attempt.

Any idea how to make it running ?

foreach( (slot value) ebb1->?
printf("%s\n" slot))
/* The statement below can not work as slot is not treated as a
variable.
How to make it right ? */
printf("%L\n" ebb1->slot);
)
What you're looking for is get(ebb1 slot).

Note that the -> operator is equivalent to getq(), which means the second argument (slot) is not
evaluated ; since the slot name - which you want to access - is in the value of the slot variable
(symbol), you need to evaluate it by using get().


Stéphane
 
On Aug 12, 4:35 am, "S. Badel" <stephane.ba...@REMOVETHISepfl.ch>
wrote:
Here is my (not working ) attempt.

Any idea how to make it running ?

foreach( (slot value) ebb1->?
printf("%s\n" slot))
/* The statement below can not work as slot is not treated as a
variable.
How to make it right ? */
printf("%L\n" ebb1->slot);
)

What you're looking for is get(ebb1 slot).

Note that the -> operator is equivalent to getq(), which means the second argument (slot) is not
evaluated ; since the slot name - which you want to access - is in the value of the slot variable
(symbol), you need to evaluate it by using get().

Stéphane
Also,

ebb1->??

is useful for examining an unkown structure.
 

Welcome to EDABoard.com

Sponsor

Back
Top