Wolfgang Helbig wrote:
Hi,
Using blockwrite with Anyfile surprises me:
The type definitions are: byteFile= file of packed record b: eightbits end; eightbits = 0..255;
And the variables: dvibuf: array [0..800] of eightbits; dvifile: byteFile;
The file is opened by rewrite(dvifile, filename) and then written by procedure writeit(f: anyfile); begin blockwrite(f, dvibuf[0..211], 212) end;
I expected to get a file with 212 bytes like this one: osx $ od -tu1 expected 0000000 247 2 1 131 146 192 28 59 0 0 0 0 3 232 27 32
But instead I get this file, the length is correct, but every byte occupies 32 bit, the higher bytes are not written at all.
osx $ od -tu1 unexpected 0000000 247 0 0 0 2 0 0 0 1 0 0 0 131 0 0 0 0000020 146 0 0 0 192 0 0 0 28 0 0 0 59 0 0 0
All this is done with gpc version 20070904 on Mac OS X 10.6.2.
I want to make minimal use of GPC extensions, thats why I didn't use the GPC byte for eight_bits or didn't use packed on subranges. I'd prefer to use packed file of eightbits instead, but GPC ignores packed for files.
And then I'd like to use buffered output without changing the source file!
Declaration for 'dvifile' does not matter. 'blockwrite' simply writes content of 'dvibuf', exactly how it is stored in memory. AFAICS you want:
dvibuf: packed array [0..800] of eightbits;
GPC simply stores each record in a separate machine word. Compare 'SizeOf(dvibuf)' with both your original declaration and with packed added.