Relay-Version: version B 2.10 5/3/83; site utzoo.UUCP Posting-Version: version B 2.10.2 9/18/84; site gumby.UUCP Path: utzoo!watmath!clyde!burl!ulysses!allegra!mit-eddie!godot!harvard!seismo!uwvax!gumby!g-frank From: g-frank@gumby.UUCP Newsgroups: net.lang.mod2 Subject: variable-length dynamic objects Message-ID: <262@gumby.UUCP> Date: Wed, 30-Jan-85 08:37:14 EST Article-I.D.: gumby.262 Posted: Wed Jan 30 08:37:14 1985 Date-Received: Sat, 2-Feb-85 00:33:46 EST Distribution: net Organization: U of Wisconsin CS Dept Lines: 67 > From: sher > > Sometime in the recent past I had read on the net how modula 2 was a strongly > typed language but flexible enough for system programming and one > which had data encapsulation built into the language. I thought "How > neat! just the language to do image hacking in!" This did not work. > I ran immeadiately into this problem. I needed to store images in a > data structure. This data structure should be able to store any image > whose elements were of the right type. Thus I started to write: > TYPE Image = RECORD > number_cols : CARDINAL; > number_rows : CARDINAL; > image : ??? > > > There is no way to have a streach array in MODULA 2! The only > variable size data structure is a linked list! (Only a lisp hacker > would store an image in a linked list). Don't tell me about > extensions to the language in various implementations. If I have to > extend the language to do something trivial like this then that > language is worthless! > > Note I have just speant 8 hours trying to get some code working that > trys to allocate arrays whose size is only known at runtime. I tried > to use the supplied loopholes and even tried using a C allocation > routine. I am now giving up on this worthless language and will code > from now on in C happy in the knowledge that there still is not another > supported (at least here) language that is usable. > > (Another hole in Modula 2 that have been commented on are that > one can not have constants whose values are hidden (not from the code > but from the code writer). > > -David Sher I can sympathize with your frustration in this case. Learning a new way to approach a problem in a new language can cause these kinds of sentiments in the best of programmers. However, I would like to draw your attention to page 161 of the second edition of Wirth's book: The type ADDRESS is defined as ADDRESS = POINTER TO WORD It is compatible with all ponter types, and also with the type CARDINAL. Therefore, all operators for integer arithmetic apply to operands of this type. Hence, the type ADDRESS can be used to perform address computations and to export the results as pointers. Also note on page 158 the existence of the procedure ALLOCATE from module Storage, which takes a var address parm and a cardinal size, and allocates a module of the requested size. Your record, as described above, can contain the horizontal and vertical sizes, and a variable of type ADDRESS, pointing to a buffer allocated in this fashion, and functions may be defined to ref- erence locations within this image array in any way you wish, with the caveat that no array bounds checking will be possible. Actually, I like the idea of arrays whose sizes may be determined at run time. You won't find them in C, though. Try Ada. -- Dan Frank "good news is just life's way of keeping you off balance."