Newsgroups: comp.sys.apple2.programmer Path: news.uiowa.edu!hobbes.physics.uiowa.edu!math.ohio-state.edu!howland.reston.ans.net!news.starnet.net!wupost!waikato!comp.vuw.ac.nz!actrix.gen.nz!dempson From: dempson@atlantis.actrix.gen.nz (David Empson) Subject: Re: Orca/M ? Message-ID: Sender: news@actrix.gen.nz (News Administrator) Organization: Actrix - Internet Services Date: Fri, 28 Apr 1995 12:29:53 GMT References: <374177331wnr@contech.demon.co.uk> X-Nntp-Posting-Host: atlantis.actrix.gen.nz Lines: 109 In article , Stephen Carpenter wrote: > what is the clc FAQ? The FAQ for the comp.lang.c newsgroup. > my big problem with the pointers in C is that they have to be a pointer TO > something. Not necessarily. You can have a pointer of type "void *", which is a pointer to anything. You can also use type-casts to convert pointer types at will (though this is not always portable; not an issue if you are writing IIgs-specific code). > A good example is patching the toolbox: The first memory location is > an interger : Fine > Then I must move to where to put the address of my routine to replace > the old one. --I want to just move the pointer and use it rather than > using unions and stuff even though the memory works out fine - C wont > compile because of a type conflict A function pointer table can either be treated as an array of long integers, or you can declare a struct type to deal with it (which is preferable). e.g. typedef struct { unsigned long routineCount; Pointer func[1]; /* Actually more than one, but this doesn't matter as long as the actual length is known. */ } FPT; typedef FPT *FPTPtr; FPTPtr get_FPT(Boolean user, Word toolSetNum) { Pointer theFPT; theFPT = GetTSPtr(user ? 0x8000 : 0, toolSetNum); return (FPTPtr)theFPT; } Boolean patch_FPT(FPTPtr theFPT, Word funcNum, Pointer theFunc) { /* A few MAJOR assumptions here: we don't want to create a function that is numbered higher than the last existing function, and the function pointer table is already in RAM. */ if (funcNum == 0 || funcNum >= theFPT->routineCount) return FALSE; /* Bad function number */ theFPT->func[funcNum - 1] = (Pointer)((long)theFunc - 1); return TRUE; } void set_FPT(Boolean user, Word toolSetNum, FPTPtr theFPT) { SetTSPtr(user ? 0x8000 : 0, toolSetNum, (Pointer)theFPT); } If you just treat the function pointer table as an array of long integers, the code is slightly simpler: typedef unsigned long *FPTPtr; FPTPtr get_FPT(Boolean user, Word toolSetNum) { Pointer theFPT; theFPT = GetTSPtr(user ? 0x8000 : 0, toolSetNum); return (FPTPtr)theFPT; } Boolean patch_FPT(FPTPtr theFPT, Word funcNum, Pointer theFunc) { /* A few MAJOR assumptions here: we don't want to create a function that is numbered higher than the last existing function, and the function pointer table is already in RAM. */ if (funcNum == 0 || funcNum >= theFPT[0]) return FALSE; /* Bad function number */ theFPT[funcNum] = (long)theFunc - 1; return TRUE; } void set_FPT(Boolean user, Word toolSetNum, FPTPtr theFPT) { SetTSPtr(user ? 0x8000 : 0, toolSetNum, (Pointer)theFPT); } > I am basicaly looking for a languge that makes dealing with memory > easy (and is unquestioning in my superior judgement) C is the closest you will get to a language that doesn't get in your way too much, without forcing you to worry about a lot of tedious detail (assembly language). Most other high level languages try even harder to keep you away from the low-level details of the machine. > If assembly wont make tasks less cumbersome - then what s it good for? Speed and doing things that cannot easily be done in high level languages (e.g. writing programs that must obey particular structures, such as drivers, interrupt handlers). > Does it make dealing with memory easier? You can do anything you like with memory in assembly language, but working out how to do it, and getting it right, can be tricky. -- David Empson dempson@actrix.gen.nz Snail mail: P.O. Box 27-103, Wellington, New Zealand