Re: C TRANSLATIONS

 BBS: Inland Empire Archive
Date: 03-16-93 (09:46)             Number: 171
From: JERRY COFFIN                 Refer#: NONE
  To: BRICE FLECKENSTEIN            Recvd: NO  
Subj: Re: C TRANSLATIONS             Conf: (3) Dr_Debug

On (11 Mar 93) Brice Fleckenstein wrote to Jerry Coffin... BF> Basic's "PEEK" and "POKE" are functionally equivilent to C pointers BF> for virtually all usage, though they MAY be a bit harder to use in BF> some BASIC implimentations. All this statement proves is that you've never used a language that supports pointers. While it might be possible to simulate pointers with peek and poke, it's going to a messy kludge at best under ANY implementation. Take a look at the following instance: struct tree { struct tree *left, *right; /* for now we'll just use a single integer in as the key to * the data being stored in the tree. In typical use, there * will be more data, but it's more or less irrelavant to * manipulating the tree itself... */ int key; } struct tree *root; This would be used to build up a binary tree. The two pointers ( left and right ) point to the descendents of a given node. ( ie. it's left and right subtrees ) Now if we want to search for something in the tree ( for instance ) it becomes a simple operation like this: struct tree *find(int key, struct tree *root) { if (NULL == root ) return NULL; else if (key == root -> key ) return root; else if (key < root -> key ) return find(key,root->left); else return find(key,root->right); } Now you may be able to kludge up something with taking the address of a subtree, poking that value into a variable large enough to hold it. Later you could peek at that value and find that item at that address. However, first off, since a pointer is normally going to be more than one byte, you're going to have to break the address up into individual bytes to place in the 'pointer' and put them back together when you read it. You're also ( to make any of it useful ) write your own dynamic allocation routines since BASIC doesn't have them built in either. Simply put, it BASIC is so thoroughly deficient in this area that it's considerably EASIER to do it in assembly instead. Later, Jerry. --- PPoint 1.38 * Origin: Point Pointedly Pointless (1:128/77.3)
Outer Court
Echo Basic Postings

Books at Amazon:

Back to BASIC: The History, Corruption, and Future of the Language

Hackers: Heroes of the Computer Revolution (including Tiny BASIC)

Go to: The Story of the Math Majors, Bridge Players, Engineers, Chess Wizards, Scientists and Iconoclasts who were the Hero Programmers of the Software Revolution

The Advent of the Algorithm: The Idea that Rules the World

Moths in the Machine: The Power and Perils of Programming

Mastering Visual Basic .NET