Relay-Version: version B 2.10 5/3/83; site utzoo.UUCP Path: utzoo!mnetor!uunet!husc6!rutgers!labrea!decwrl!hplabs!hpcea!hpsrla!hpsrlc!darrylo From: darrylo@hpsrlc.HP.COM (Darryl Okahata) Newsgroups: comp.sys.ibm.pc Subject: Re: Turbo C memset problem Message-ID: <3320068@hpsrlc.HP.COM> Date: Sat, 14-Nov-87 20:03:53 EST Article-I.D.: hpsrlc.3320068 Posted: Sat Nov 14 20:03:53 1987 Date-Received: Mon, 16-Nov-87 04:50:13 EST References: <238@cunixc.columbia.edu> Organization: HP Network Measurements Div - Santa Rosa, CA Lines: 41 In comp.sys.ibm.pc, nwc@cunixc.columbia.edu (Nick Christopher) writes: > I had code that was very happy in the small model in which I blanked and > character array using memset as follows: > > char string[80] > > memset(string,NULL,80); > > however when I moved to large model this no longer worked, it began to have > the exact same 3 garbage characters at the begining of string. Is this the > fault of my format or the memset's fault. > > /nwc > -- > "I am the Lorvax. I speak for the machines." > ______________________________________________________________________________ > nwc%cunixc@columbia, columbia!cunixc!nwc BITNET: nwcus@cuvma > USENET: topaz!columbia!cunixc!nwc > ---------- The second argument to memset() is supposed to be a character: in place of a character, you have "NULL" which typically represents a NULL pointer (strictly speaking, a null pointer should be "(char *) NULL", not just "NULL" -- but that's another story). To fix your problem, use: memset(string, '\0', 80); Your problem stems from the use of "NULL" instead of a character; in the small memory model, the use of "NULL" pushes a word (16 bits) onto the stack for the second argument, whereas, in the large memory model, two words, instead of just one, are pushed on the stack. As a result, the stack was misaligned, and memset() could not properly access its arguments. -- Darryl Okahata {hplabs!hpccc!, hpfcla!} hpsrla!darrylo CompuServe: 75206,3074 Disclaimer: the above is the author's personal opinion and is not the opinion or policy of his employer or of the little green men that have been following him all day.