Difference between revisions of "Talk:Dynamic array"
From Free Pascal wiki
Jump to navigationJump to search (FillChar / SizeOf) |
|||
Line 1: | Line 1: | ||
− | I was a little bit confused about the sentence "''To init such an invalid pointer you have to use '''FillChar(MyVariable,sizeof(MyVariable), #0)'''.''" This might be misleading, as this fills the '''pointer''' to MyVariable with the size of this pointer with zeros, not the array itself, as far as I | + | I was a little bit confused about the sentence "''To init such an invalid pointer you have to use '''FillChar(MyVariable,sizeof(MyVariable), #0)'''.''" This might be misleading, as this fills the '''pointer''' to MyVariable with the size of this pointer with zeros, not the array itself, as far as I understand. This might be different to static arrays (didn't prove that). |
Anyway: It took me some time to find out, how to initialize the array itself: | Anyway: It took me some time to find out, how to initialize the array itself: |
Revision as of 12:13, 11 August 2014
I was a little bit confused about the sentence "To init such an invalid pointer you have to use FillChar(MyVariable,sizeof(MyVariable), #0)." This might be misleading, as this fills the pointer to MyVariable with the size of this pointer with zeros, not the array itself, as far as I understand. This might be different to static arrays (didn't prove that).
Anyway: It took me some time to find out, how to initialize the array itself: FillChar(MyVariable[0], Length(MyVariable) * SizeOf(TheArrayType), #0);
Perhaps this difference between initializing the array itself and the reference to the array should be emphasized? Or did I misunderstand something there?