Path: utzoo!utgpu!water!watmath!clyde!att!rutgers!ucsd!nosc!helios.ee.lbl.gov!pasteur!ucbvax!ANDREW.CMU.EDU!sh1u+ From: sh1u+@ANDREW.CMU.EDU (Stuart Mark Hiser) Newsgroups: comp.os.vms Subject: Re: testing if a file is open from pascal Message-ID: Date: 28 May 88 19:54:42 GMT Sender: daemon@ucbvax.BERKELEY.EDU Organization: The Internet Lines: 28 > 2) Any ideas why the following blurb of code results in an access > violation?? I've been bitten by this myself: the problem is that in a pascal varying of character, the length of the string is maintained explicitly in a separate register, whereis C doesn't - it expects strings to end with a null byte. Printf is looking down the string, trying to find the null byte (that isn't there), and eventually reaches the end of its address space -> access violation. This worked for me: str_ptr->dsc$a_pointer[length] = '\0'; (note: dsc$w_length is the maximum length, not necessarily the current length) Two other things you should be aware of: 1: Pascal generally passes strings by reference, not by descriptor; to use descriptors, change your declaration to: [EXTERNAL] function Is_it_open(str: %descr string):integer; extern; 2: For a varying string, the first two bytes of dsc$a_pointer will contain the current length of the string; the actual string data will start at third byte. [ keep in mind this is all from memory - I don't have my manuals handy :-) ] Stu Hiser R746SH1U@VB.CC.CMU.EDU VAX/VMS system programmer R746SH1U@CMCCVB.BITNET Carnegie Mellon University CMCCVB::R7467SH1U (CCnet)