print values of a struct without knowing the slot names

  • Follow


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);
)

0
Reply Rolf.Kemper (44) 8/12/2008 10:00:35 AM

> 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
0
Reply stephane.badel1 (446) 8/12/2008 10:35:58 AM


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 va=
lue of the slot variable
> (symbol), you need to evaluate it by using get().
>
> St=E9phane

Also,

ebb1->??

is useful for examining an unkown structure.
0
Reply joel_cooper (18) 8/13/2008 3:25:37 PM

2 Replies
40 Views

(page loaded in 0.059 seconds)

Similiar Articles:













7/18/2012 9:53:06 AM


Reply: