Wood David wrote:
Am I right in assuming that the dynamic array sizing is tacked on the end of the storage so deducting 4 words per dimension is the right approach?
Schemata contain their discriminants just as declared, i.e., 4 bytes (not words!?) for `Integer' on most systems. They're similar to records, with the discriminants at the front(!).
Is Initialize() only required after I've zeroed a string or a record containing a string?
Maurice and I have said which types require initialization (besides types with explicit initializers, of course). But the list is not guaranteed to be complete for all times ...
Finally, given that Initialize can very usefully take any variable as a parameter, it's a shame that it doesn't actually do the zeroing.
One doesn't always want to do the zeroing (which can be substantially more work for large structures) when initializing. Using `FillChar' and `Initialize' explicitly is just what the compiler would do if it would include the zeroing (unless you'd expect it, e.g., to initialize reals to the floating point 0.0 representation which AFAIK isn't necessarily all zero bytes).
BTW, EP initializers would help here since you could just initialize the array to zero. Unfortunately, they're not completely implemented in GPC yet (and this case is missing) ...
- If sizeof() reports a dynamic variable (e.g.. an array of 3 doubles) to
be, say, 28 bytes, which we understand to be 3 x 8 + 4 for the dynamic size, the total size of the Pascal storage area is 28. So why should linking with efence produce a SIGSEGV anyway when using memset on this area?
The problem is with the untyped parameter: It's basically not clear what should be passed, the whole schema or just the array. When the whole schema is passed, `SizeOf' would be correct, but when the array is passed, you'd need the size of the array only (which, AFAICS, cannot be easily obtained).
If the parameter is declared either as `Dyn_arr' or as an open/conformant array (`array of Integer' or `array [a .. b: Integer] of Integer'), it would be clear either way. But an untyped parameter principally allows for both (yet another caveat with untyped parameters).
I think I agree that passing the whole schema would be more reasonable. If there's consensus, I think we can make it the (documented) behaviour in future GPC versions. (Perhaps you can write some test programs ...)
Frank