Re: Help on disassembler/decompilers

markh@csd4.csd.uwm.edu (Mark William Hopkins)
19 Sep 90 03:02:25 GMT

          From comp.compilers

Related articles
[21 earlier articles]
Re: Help on disassembler/decompilers kym@bingvaxu.cc.binghamton.edu.cc.binghamton.edu (1990-09-15)
Re: Help on disassembler/decompilers roland@ai.mit.edu (1990-09-16)
Re: Help on disassembler/decompilers raulmill@usc.edu (1990-09-16)
Re: Help on disassembler/decompilers ch@dce.ie (1990-09-18)
Re: Help on disassembler/decompilers ctl8588@rigel.tamu.edu (1990-09-18)
Re: Help on disassembler/decompilers megatest!djones@decwrl.dec.com (1990-09-18)
Re: Help on disassembler/decompilers markh@csd4.csd.uwm.edu (1990-09-19)
Re: Help on disassembler/decompilers td@alice.UUCP (1990-09-21)
| List of all articles for this month |

Newsgroups: comp.compilers
From: markh@csd4.csd.uwm.edu (Mark William Hopkins)
Keywords: assembler, debug, disassemble
Organization: University of Wisconsin-Milwaukee
References: <HOW.90Sep5173755@sundrops.ucdavis.edu> <6839.26ea3b0e@vax1.tcd.ie> <3972@bingvaxu.cc.binghamton.edu> <1990Sep14.181616.26890@dce.ie>
Date: 19 Sep 90 03:02:25 GMT

In article <1990Sep14.181616.26890@dce.ie> ch@dce.ie (Charles Bryant) writes:
>Well how would you translate this C function into Pascal.
>
> typedef struct list {
> struct list *next;
> int item;
> } list;
>
> list *head;
>
> insert(list *newelem)
> {
> list **p;
> for (p = &head; *p; p = &(*p)->next)
> if ( (*p)->item >= newelem->item) break;
> newelem->next = *p;
> *p = newelem;
> }
...
>It seems to me that you either need an extra node, or you have to simulate the
>pointers in an array. If you manage the Pascal, try BASIC (even with no
>pointer operations at all it is still "equivalent" to C).


By first translating it into Proper C...


[A] Change the 'list = struct list' into 'list = struct list *', and
        make the original program readable :).


typedef struct List {
      struct List *Next; int Item;
} *List;


List Head;


Insert(List NewElem) {
      List *P;
      for (P = &Head; *P != NULL; P = &(*P)->Next)
            if ((*P)->Item >= NewElem->Item) break;
      NewElem->Next = *P;
      *P = NewElem;
}


[B] Add in a dummy variable, dP, to represent *P.


Insert(List NewElem) {
      List *P, dP;


      for (P = &Head, dP = *P; dP != NULL; P = &dP->Next, dP = *P)
            if (dP->Item >= NewElem->Item) break;
      NewElem->Next = dP;
      dP = *P = NewElem;
}


[C] Use semantic equalities to make P go away...


Insert(List NewElem) {
      List *P, dP;


      for (P = &Head, dP = Head; dP != NULL; P = &dP->Next, dP = dP->Next)
            if (dP->Item >= NewElem->Item) break;
      NewElem->Next = dP;
      *P = NewElem; dP = NewElem;
}


[D] Make P go away, and make believe that dP was P all along...


Insert(List NewElem) {
      List P;


      for (P = Head; P != NULL; P = P->Next)
            if (P->Item >= NewElem->Item) break;
      NewElem->Next = P; P = NewElem;
}


Proper C is a beautiful subset of C, in which all non-system identifiers are
syntatically required to begin in capitals, all "&"'s are removed, and all
recursively defined structures are required to have pointers to that structure
with the same name as the structure...


See? No new node. You closed your eyes in steps [B] and [C], didn't you? :)
--


Post a followup to this message

Return to the comp.compilers page.
Search the comp.compilers archives again.