[fpc-pascal] Re: Library for network calculation
Sven Barth
pascaldragon at googlemail.com
Wed Jul 27 18:54:53 CEST 2011
On 27.07.2011 12:22, Dimitri Smits wrote:
> don't have a Delphi in reach for the moment to verify, but you could do that to a const (if you enable the assignable constants setting)
>
> procedure SomeProc;
> const
> someconst: Integer = 22;
> begin
> //blabla
> someconst := 42;
> //yadda yadda
> end;
>
In this case "someconst" will keep the assigned value during different
functions calls.
For example:
=== source begin ===
procedure SomeProc;
const
someconst: Integer = 21;
begin
if someconst = 42 then
Writeln('The answer')
else begin
Writeln('Not the answer');
someconst := 42;
end;
end;
begin
SomeProc;
SomeProc;
end;
=== source end ===
will print:
=== output begin ===
Not the answer
The answer
=== output end ===
This was considered as the equivalent of a local static variable.
In case of "var" the definitions are normal variables and semantically
equivalent to an initialization of the variable at the beginning of the
function.
Regards,
Sven
>
> ----- "Sven Barth"<pascaldragon at googlemail.com> schreef:
>
>> Well... seems like you didn't notice this feature yet :D
>>
>> I'm talking about this:
>>
>> === source begin ===
>>
>> procedure SomeProc;
>> var
>> somevar: Integer = 42;
>> begin
>>
>> end;
>>
>> === source end ===
>>
>> This works in FPC, but doesn't in Delphi ;)
>>
>> Regards
>> Sven
>>
>> Am 26.07.2011 21:27, schrieb Jorge Aldo G. de F. Junior:
>>> I dont like to take local variable initialization for granted.
>>>
>>> Even if the manual says that its guaranteed that a local variable
>> will
>>> start with 0,
>>> i prefer to initialize everything to a known value myself.
>>>
>>> An aditional
>>>
>>> Move $varaddress, 00
>>>
>>> at startup wont slow things down noticeably when your pc is running
>> at 2ghz...
>>>
>>> This unit needs to take care of big endian vs. low endian (maybe a
>> $define ?)
>>>
>>> When i wrote that code i did not pay attention to this...
>>>
>>> Anything more complex (like interacting with DHCP server) would be
>> too
>>> complex and probably dependent on external units (like synapse x
>> lnet
>>> etc). Some people might prefer to use other library instead of the
>>> default choosen one, etc...
>>>
>>> 2011/7/26 Sven Barth<pascaldragon at googlemail.com>:
>>>> On 26.07.2011 01:23, Paul Nicholls wrote:
>>>>>
>>>>> "Jorge Aldo G. de F. Junior"
>>>>> <jagfj80 at gmail.com> wrote in message
>>>>>
>> news:CAAHHabS9aUe9gwyNjkve-XVXsRyf2UPsArh6=fSDPGoKugjfsA at mail.gmail.com...
>>>>>>
>>>>>> Some time ago someone asked for a library able to do network
>>>>>> calculations.
>>>>>>
>>>>>> Here is something that might evolve into such library :
>>>>>>
>>>>> <SNIP>
>>>>>>
>>>>>> Function NetMaskToHostMask(NetMask : TNetworkIP): TNetworkIP;
>>>>>> Begin
>>>>>> Result.Mode := False;
>>>>>> NetMask.Mode := False;
>>>>>> Result.IP := NetMask.IP Xor %11111111111111111111111111111111;
>>>>>> End;
>>>>>>
>>>>> <SNIP>
>>>>>
>>>>> I didn't know that freepascal handled binary formatted numbers?!?
>>>>>
>>>>> %11111111111111111111111111111111
>>>>
>>>> There are often new things one can learn about what FPC supports ;)
>> (though
>>>> binary numbers are already old for me ^^)
>>>>
>>>> The most recent finding (at least for me) was the abbility to
>> initialize
>>>> local variables.
>>>>
>>>> Regards,
>>>> Sven
>>>>
>>>> _______________________________________________
>>>> fpc-pascal maillist - fpc-pascal at lists.freepascal.org
>>>> http://lists.freepascal.org/mailman/listinfo/fpc-pascal
>>>>
>>> _______________________________________________
>>> fpc-pascal maillist - fpc-pascal at lists.freepascal.org
>>> http://lists.freepascal.org/mailman/listinfo/fpc-pascal
>>
>> _______________________________________________
>> fpc-pascal maillist - fpc-pascal at lists.freepascal.org
>> http://lists.freepascal.org/mailman/listinfo/fpc-pascal
> _______________________________________________
> fpc-pascal maillist - fpc-pascal at lists.freepascal.org
> http://lists.freepascal.org/mailman/listinfo/fpc-pascal
More information about the fpc-pascal
mailing list