Path: utzoo!utgpu!news-server.csri.toronto.edu!cs.utexas.edu!usc!snorkelwacker!mintaka!spdcc!esegue!compilers-sender From: markh@csd4.csd.uwm.edu (Mark William Hopkins) Newsgroups: comp.compilers Subject: Re: Help on disassembler/decompilers Keywords: assembler, debug, disassemble Message-ID: <6412@uwm.edu> Date: 19 Sep 90 03:02:25 GMT References: <6839.26ea3b0e@vax1.tcd.ie> <3972@bingvaxu.cc.binghamton.edu> <1990Sep14.181616.26890@dce.ie> Sender: compilers-sender@esegue.segue.boston.ma.us Reply-To: markh@csd4.csd.uwm.edu (Mark William Hopkins) Organization: University of Wisconsin-Milwaukee Lines: 83 Approved: compilers@esegue.segue.boston.ma.us 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? :) -- Send compilers articles to compilers@esegue.segue.boston.ma.us {ima | spdcc | world}!esegue. Meta-mail to compilers-request@esegue.