SizeOf(somePtr^) should never return "Variable not initialized"
Original Reporter info from Mantis: zex2011
-
Reporter name: Zex Atilla
Original Reporter info from Mantis: zex2011
- Reporter name: Zex Atilla
Description:
I have to re-report this, because it was closed and there's something to add to it. In the following example:
procedure Test;
type
TMyRecord = record;
a: byte;
b: integer;
end;
var
x: ^TMyRecord;
begin
GetMem (x, SizeOf (x^));
end;
FPC says: "Warning: Local variable X does not seem to be initialized". Your answer was: "It's the evaluation of ^ that generates the problem".
The solution would be:
Make SizeOf never generate the "Not initialized" problem. No matter what is computed inside it.
Shouldn't compiler have contextual states, to generate different errors when compiling static than dynamic parts? When evaluating SizeOf it should behave as if evaluating the CONST section. Because SizeOf is a CONST declaration, isn't it?
This is important because many programmers (including me) are using SizeOf(ptr^) to automatically evaluate the correct type. So, if one day I change the declaration of variable to X: TNewMyType automatically all SizeOf calls will return the size of TNewMyType instead of TMyTRecord. This reduces possible errors and makes code easier to maintain (no refactoring).
Mantis conversion info:
- Mantis ID: 20356
- OS: All
- OS Build: All
- Platform: All
- Version: 2.7.1