Path: utzoo!utgpu!news-server.csri.toronto.edu!cs.utexas.edu!samsung!zaphod.mps.ohio-state.edu!wuarchive!kuhub.cc.ukans.edu!markv From: markv@kuhub.cc.ukans.edu Newsgroups: comp.sys.amiga.tech Subject: Re: Excruciatingly simple programming question... Message-ID: <25060.26b5903c@kuhub.cc.ukans.edu> Date: 31 Jul 90 19:05:47 GMT References: <4106@dogie.macc.wisc.edu> Organization: University of Kansas Academic Computing Services Lines: 93 In article <4106@dogie.macc.wisc.edu>, gilmore@vms.macc.wisc.edu (Neil Gilmore) writes: > This is much simpler than the discussions which normally come up here, > but the only other Amiga programmer I see regularly doesn't know how to > do anything other than open a new screen (but at least now he programs > so that he exits cleanly, though the program grabs the entire system > while it's running). > > What I'm using: > > Manx 3.6b? (question on the 'b', not the 3.6) I think this is the problem. > #include "libraries/dosextens.h" This is the only include. No prototypes (of course being a Lattice person I don't even know if Manx 3.6x supports them). However... > extren struct FileHandle *Open(); > > main() > { > char userinput[256]; > Write(dos_fh,"Please type an input line, then press RETURN\n", 45); In Manx, ints (and unnamed integer quantities) default to 16 bits. If memory serves me write (sorry, bad pun), most DOS functions expect 32 bit numbers (so you can do BIG reads and writes in one shot). If you execute this function call and Manx defaults to short ints, you will get a 16 bit representation of 45 pushed on the stack. The stub in amiga.lib will will pull of what it expects to be a 32 bit int, which means you will get 16 bits of random garbage (which is guarenteed to create a number a lot bigger than 45). The solution is to use prototypes or casts. Try including "exec\types.h" to get the Amiga standard types, and then try you call like: Write(dos_fh,"Please type blah blah blah \n", (ULONG) 45); Or maybe it should be (LONG), but it shouldn't make a difference here. The point is your casting it to a 32 bit int which results in a 32 bit representation of 45 getting pushed on the stack. > howmany = Read(dos_fh,userinput,255); Same here type (ULONG) 255. > When I remove the Write(), the Read() works only if I do not type too > many characters to the created CON: window. Too many is 'some more' than > 255. Again, length seems to be ignored, but the AD MAnual does not > explicitly say that only length characters will be read. Typing too many > characters results in the 'Task Held' requester, and a guru. AmigaDOS will not overrun the length passed, but since its gettng some random number (a lot bigger than 255), its' overrunning your buffer after you type too many charecters. > After spending much time trying to get this to work, I gave up and tried > listing 2.2, essentially the same program using a RAW: window. Though > this program had no Write(), Read() again acted in an unexpected > fashion. Read() would return after each character typed, presumably > returning the correct character code, but actualLength was gibberish, > not 0, 1, -1, or any recognizable number. Probably a similar problem. Read is plugging in a 32 bit value to your 16 bit int. > There is probably a one sentence explanation for this, perhaps one of > the differences between Manx and Lattice, but until I can get this sort > of program to work, there isn't much hope for producing anything useful. Lattice uses 32 bit ints by default (although you can use 16). Manx uses 16. In general either cast everything, or compile with 32 bit ints (and make you link with 32 bit libs like cl32.lib instead of cl.lib). Or upgrade to Manx 5.0 or buy Lattice. Function prototypes solve this whole problem if you use them (with lattice I just #include and I have prototypes for every system function. > > Thank you. Good luck, -- ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ Mark Gooderum Only... \ Good Cheer !!! Academic Computing Services /// \___________________________ University of Kansas /// /| __ _ Bix: markgood \\\ /// /__| |\/| | | _ /_\ makes it Bitnet: MARKV@UKANVAX \/\/ / | | | | |__| / \ possible... Internet: markv@kuhub.cc.ukans.edu ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~