Usenet comp.sys.dec (1990-2013)
 help / color / mirror / Atom feed
From: cowan@btgmax.zko.dec.com (Ken Cowan)
Subject: Re: DEC C / VAX C problems
Date: 18 Jan 1994 20:11:29 GMT	[thread overview]
Message-ID: <2hhfph$bbd@jac.zko.dec.com> (raw)
In-Reply-To: 1994Jan14.104449@rzhp9a.gsi.de


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


      parent reply	other threads:[~1994-01-18 20:11 UTC|newest]

Thread overview: 3+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
1994-01-14  9:44 DEC C / VAX C problems Matthias Kaspar
1994-01-14 18:21 ` Steve Hobbs
1994-01-18 20:11 ` Ken Cowan [this message]
read-only archive

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox