Re: Link list problem



In article <1121686911.974617.173390@xxxxxxxxxxxxxxxxxxxxxxxxxxxx>,
Shwetabh <shwetabhgoel@xxxxxxxxx> wrote:
>Hi,
>This is a question asked to me in an interview.
>I haven't been able to figure out an answer for
>it. Please try to see what can be done about the
>following problem.
>
>/* I have been given two structures */
>struct node
>{
> struct node *next;
>} *temp;
>
>struct data
>{
> int a;
> float b;
> char c;
> struct node s;
>};
>
>/* Now the question is to access the values of a,b,c using temp */
>
>Thanks in advance.
>

Ick.
The first thing I'd say is "I hope the code at this company doesn't do
silly things like this."
The second thing is that I'd use the macro "offsetof" along with some creative
casting and pointer arithmetic to transform a "struct node *" into
a "stuct data *". The rest is trivial.

But once again, I'd want an assurance that the above silliness isn't standard
practice at the company you're applying for a job at.
.



Relevant Pages

  • Re: Benchmark: STLs list vs. hand-coded one
    ... and create a temporary string by concatenating them with spaces between ... Ok, I'll do a benchmark according to this, when I have some time. ... struct Data array; ... struct Node next; ...
    (comp.arch.embedded)
  • Re: Link list problem
    ... > struct node *next; ... A pointer to an object or incomplete type may be ...
    (comp.lang.c)
  • Re: Benchmark: STLs list vs. hand-coded one
    ... struct Data array; ... struct Node next; ... You seem to be quite awake, ... like a good way to stress out the memory allocator! ...
    (comp.arch.embedded)
  • Re: Link list problem
    ... > struct node *next; ... struct data *next; ... which temp is a pointer to a struct data instead of a struct node. ...
    (comp.lang.c)
  • Re: Print linked list backwards
    ... In an interview for an embedded software position recently I was ... struct node *next; ... void revprint(struct node *root) { ...
    (comp.lang.c)