Can anything bad happen, if I clear my array by assigning a non-initialized array to it in pascal?
delphi, freepascal, pascal
Solution
This is absolutely fine. The semantics of the code are exactly what you need. Certainly the Delphi compiler will emit code to perform a simple and efficient memory copy. The compiler is able to do that because you have a fixed length array whose elements are simple value types. I'd be surprised if FPC did not produce very similar code.
Even if your array contained managed types (it doesn't), the assignment operator would result in code that respected those managed types.
As a final comment, the array full of zeros should be a constant.
Problem
In pascal, the only way I dared cleaning my array was to simply iterate through it and clear it, but it is extremely inefficient. Can't I simply reinitialize it by assigning an empty array to it? ``` program arrays; var working, empty : array [1..10] of integer; begin working[3] := 5; working:= empty; end. ``` Is is ok to do this, can this backfire?