From mboxrd@z Thu Jan 1 00:00:00 1970 X-Google-Language: ENGLISH,ASCII-7-bit X-Google-Thread: 1164f8,7cd9a3746a6022b2 X-Google-Attributes: gid1164f8,public X-Google-ArrivalTime: 1994-01-18 13:19:27 PST Path: gmd.de!newsserver.jvnc.net!yale.edu!yale!gumby!destroyer!news.cic.net!magnus.acs.ohio-state.edu!usenet.ins.cwru.edu!howland.reston.ans.net!vixen.cso.uiuc.edu!sdd.hp.com!decwrl!pa.dec.com!nntpd.lkg.dec.com!jac.zko.dec.com!btgmax.zko.dec.com!cowan From: cowan@btgmax.zko.dec.com (Ken Cowan) Newsgroups: comp.sys.dec Subject: Re: DEC C / VAX C problems Date: 18 Jan 1994 20:11:29 GMT Organization: Digital Equipment Corporation Distribution: world Message-ID: <2hhfph$bbd@jac.zko.dec.com> References: <1994Jan14.104449@rzhp9a.gsi.de> Reply-To: cowan@btgmax.zko.dec.com (Ken Cowan) NNTP-Posting-Host: btgmax.zko.dec.com Keywords: DEC C, VAX C, SYSTEM$SPACE, fwrite In article <1994Jan14.104449@rzhp9a.gsi.de>, kaspar@rzhp9a.gsi.de (Matthias Kaspar) writes: |>Path: jac.zko.dec.com!pa.dec.com!decwrl!uunet!Germany.EU.net!netmbx.de!zrz.TU-Berlin.DE!math.fu-berlin.de!news.th-darmstadt.de!rzhp9a.gsi.de!kaspar |>From: kaspar@rzhp9a.gsi.de (Matthias Kaspar) |>Newsgroups: comp.sys.dec |>Subject: DEC C / VAX C problems |>Date: Fri, 14 Jan 94 04:44:49 EST |>Organization: GSI, Darmstadt, Germany |>Lines: 174 |>Distribution: world |>Message-ID: <1994Jan14.104449@rzhp9a.gsi.de> |>NNTP-Posting-Host: rzhp9a.gsi.de |>Keywords: DEC C, VAX C, SYSTEM$SPACE, fwrite |> |>Hi everybody |> |>Recently I got stuck with two C specific problems, one concerning DEC C on an |>OpenVMS V1.5 AXP system (DEC 3000/500), another one concerning VAX C on a |>VAXstation 4000-90, VMS-V5.5-2H4. |> |>I am by no means experienced in C so please don't flame me if the following |>questions seem obviuos to you. |> |>***************************************************************************** |>* * |>* Problem 1 Using DEC C, SYSTEM$SPACE seems to delay the computation of * |>* many functions in math.h on an OpenVMS AXP system. * |>* * |>***************************************************************************** Steve Hobbs answered this previously. The compiler can optimize away many of the calls to sin. |>******************************************************************************* |>* |>* Problem 2 Using VAX C on a VAXstation with VMS, fwrite fails |>* in case of fixed-length, record-formated files |>* |>******************************************************************************* |> |>Somehow I do not succed to use the fwrite function on a VAXstation |>4000-90 under VMS-V5.5-2H4. Please take a look at the following source... |> |>#include stdio |>main() |>{ |>float x[100]; |>int i,j; |>FILE *myfile; |> |>for (j=0;j<100;j++) x[j]=(float)j; /* just for fun */ |> |>myfile=fopen("data.dat","w","ctx=rec","rfm=fix","mrs=512","shr=get,put"); |>/*I need the record format because the files have to be shareable*/ |>perror("\nperror after fopen..."); |>if (myfile==0) printf("\nfopen returns NULL pointer..."); |>else{ |> i=fwrite(&x[0],sizeof(float), 100,myfile); |> perror("perror after fwrite... "); |> printf("\nfwrite returns...%d",i); |> fclose(myfile); |> } |> |>/*just for fun try to reopen and read the file. However, you don't need this |>part to reproduce the error*/ |> |>myfile=fopen("data.dat","r","ctx=rec","rfm=fix","mrs=512","shr=get,put"); |>perror("\nperror after fopen for read..."); |>if (myfile==0) printf("\n fopen returns NULL pointer..."); |>else{ |> i=fread(&x[0],sizeof(float),100,myfile); |> perror("perror after fread... "); |> printf("\nfread returns...%d",i); |> fclose(myfile); |> } |>} |> |> |>Now the first fopen succeds in opening the file data.dat. A $ dir data.dat/full |>tells me the file as been created correctly. The fwrite function however |>returns 0 and consequently hasn't written a single byte to the file. perror |>after the fwrite gives an error message. The output I get looks like this... |> |>perror after fopen...: error 0 |>perror after fwrite... : non-translatable vms error code: 0x186A4, vms message: |>%rms-f-rsz, invalid record size |> |>fwrite returns...0 |> |>The following lines are of course due to the attempt to read the empty file |>(I guess...) |> |>perror after fopen for read...: non-translatable vms error code: 0x186A4, vms |>message:%rms-f-rsz, invalid record size |>perror after fread... : non-translatable vms error code: 0x186A4, vms message: |>%rms-f-rsz, invalid record size |>fread returns...0 |> |>I have tried different record sizes (512, 1024, 2048, 4096, 8192 bytes), I have |>tried to write different numbers of items and different items to the file, it |>just does not work. |> |>However, compiling the source with DEC C on an OpenVMS AXP system presents no |>problems at all, the code runs as expected and does NOT generate the above |>error messages. 100 floats (400 bytes) are written to the file, fwrite correctly |>returns the number of items written, that is 100. Reading the file afterwards |>works all right too. If I take this data.dat created on an OpenVMS AXP system |>and copy it to the above VAXstation, the second part of the code succeds in |>opening and reading the file, so fread works with VAX C, just fwrite presents |>difficulties to me. |> |>What can I do about this? Is this a VMS bug? (Or am I just too stupid to use |>fwrite correctly?) |> |>Why does it work on an OpenVMS AXP system, but fails on a VAXstation? |> That fwrite call tells VAX C to write 100 records that are each 4 bytes long. The fopen statement says to create a file where every record is a fixed length, and that length is 512. RMS complains because it expects 512 and it is only given 4 at a time. Try mrs=4 if you want 4 byte records, or mrs=400 and 1 item of 400 bytes (the size of the whole array) for the fwrite(). DEC C works a little differently. It interprets the fwrite call as a desire to write 400 bytes, using as many records as necessary. I used fopen mode "wb" since the program is writing binary data. |> |>Thanks a lot for taking the time to read all this. Any comments or suggestions |>are most welcome. In case you know of any DEC Email address I might confront |>with these questions, please tell me. |> |>As I don't expect these problems to be of general interest please send replies |>to one of these Internet nodes: |> |>mkaspar@axp601.gsi.de (mkaspar@[140.181.98.71]) |>mkaspar@vscn.gsi.de (mkaspar@[140.181.97.141]) |>kaspar@IKF007.IKF.PHYSIK.UNI-FRANKFURT.DE (kaspar@[141.2.34.13]) |> |>Anyone interested in replies should send me an Email, I will of course be happy |>to forward any incomming mail. |> |>Thanks again, I really appreciate your help. |> |>Bye, |> |>Matthias Kaspar |> |> |> -- Ken Cowan, ZK2-3/Q8 cowan@rtl.enet.dec.com Digital Equipment Corporation decwrl!rtl!cowan 110 Spit Brook Rd, Nashua, NH 03062