I'm a bit injured and I can only type with one hand, so I'll pprobably be quite silent for 1-2 weeks.
I mostly agree with Waldek.
Waldek Hebisch wrote:
Well, I frequently have the same feeling. But I also keep finding blatant errors in code that "worked happily" for years. So I am very sceptical about changes that reduce error checking in the compiler. IMHO if reduced error checking is needed it should be localised, so that other parts of the program (or other programs) still are checked. One possibility could be "customisable" (skinable??) language -- where the user would specify exactly (say, in a config file) which constucts are allowed. But that would complicate GPC quite a lot...
More compiler directives ... but IHMO only if it can be reasonably supported (i.e., if taking the address at least work everywhere which doesn't seem to be the case).
I corrected similar problem (type mismatch between record field and a var parameter) in Stanford Pascal (~ 10000 lines of code, tens of calls to correct). The correction is not very nice, but after about 1 hour I was done. In your case it would look like: { In declaration section } Type tsig = array [ 0..3 ] OF Char; foo = packed record sig : tsig; end;
{ At apropriate scope} Var foo_aux : tsig; Var f : foo;
begin foo_aux := f.sig; StrCopy (foo_aux, 'OK'); f.sig := foo_aux end.
(of course for `StrCopy' there is no need for the first assignment, but I want to show general case). Tedious -- yes, but can be done quickly.
Perhaps you can just treat the array as a Pascal string (almost standard, since index isn't 1 based, but GPC allows it):
f.sig := 'OK';
If you need CString semantics, add #0 explicitly. Depending on what you actually do with it, this might work ...
If my wild guess is correct you need packed record to match file header. Then the best way may be to copy it to unpacked record on reading file and copy to packed one on writing.
Or read header in parts (packed, then unpacked for this one -- I think we can guarantee that un-/packed array of char have the same layout -- otherwise I think many things would break).
Finally, if you really want quick&dirty solution the following seem to do what you want:
program packer; uses Strings; Type {$pack-struct, maximum-field-alignment 8} foo = record sig : array [ 0..3 ] OF Char; end; {$no-pack-struct, maximum-field-alignment 0}
Var f : foo; begin StrCopy (f.sig, 'OK'); writeln (f.sig[0], f.sig[1]) end.
Actually this may be closer to the intended meaning, unless really bitfields are used.
Frank