Are there any advantages in using const parameters with an ordinal type?

前端 未结 5 1950
失恋的感觉
失恋的感觉 2020-12-05 06:54

I know marking string parameters as const can make a huge performance difference, but what about ordinal types? Do I gain anything by making them const

5条回答
  •  情话喂你
    2020-12-05 07:26

    Declaring ordinal types const makes no difference because they are copied anyway (call-by-value), so any changes to the variable do not affect the original variable.

    procedure Foo (Val : Integer)
    begin
    Val := 2;
    end;
    ...
    SomeVar := 3;
    Foo (SomeVar);
    Assert (SomeVar = 3);
    

    IMHO declaring ordinal types const makes no sense and as you say requires you to introduce local variables often.

提交回复
热议问题