On 12/28/2015 5:22 AM, Ramine wrote:
>
> Look at this example in FreePascal and Delphi:
Oh, Pascal. Pascal was roughly my 3rd main language, after a special
dialect of Basic (before GW-Basic) and Intel 8080 assembly. Well unless
you count TI 57 calculator programming, in which case Pascal came third.
I used a lot of dialects of Pascal, and had the whole syntax memorized
so I could draw syntax diagrams for the whole of Jensen & Wirth Pascal,
and most of UCSD p-Pascal and some others. But truth be told I didn't
make any interesting programs in 8080 assembly, I just tried to figure
out how that worked, and was surprised when a HLT instruction didn't
return me to the machine's built-in command interpreter, like STOP did
in Basic!
Delphi is interesting because it was the continuation of Borland Pascal,
which was the big brother of Turbo Pascal, which was the brainchild of
Anders Hejlsberg, who later design C#, mentioned below.
> ===
> program test;
In original Pascal, as I recall, you had to indicate in the above
statement that you'd be using the standard input and output streams.
> var a:integer;
>
>
> procedure test(b:Longword);
"Longword" was not an original Pascal type. I doubt that it's part of
standard Pascal. It was probably introduced with Turbo Pascal.
> begin
> writeln(b)
> end;
Oh the joys of Pascal's semicolon-as-DELIMITER. :-)
Anyway, systematic indentation is Good Idea™, in Pascal and most every
programming language.
> begin
>
> a:=3;
>
> try
> test(a);
But the above semicolon (and formal null-statement) is a bit
inconsistent with the earlier lack of semicolon.
General consistency is also Good Idea™, not just for indentation, in
Pascal and most every programming language.
> except
> writeln('problem!');
> end;
> end.
>
> ==
>
>
> If you compile this example in FreePascal with the -Cr option for
> range checking, the example above will generate an exception because
> at runtime you are trying to pass a negative number to the function
> that receive a Longword, that means that receive in C an unsigned long,
I'm not so sure that the type identification you make here is valid in
general. I would guess that FreePascal's `Longword` is a 32-bit unsigned
integer. In contrast, a C `unsigned long` can in practice be 32 or 64
bits, depending on the C compiler (in Windows it's 32 bits always), and
formally it can be any size equal or larger than 32 bits.
> so this technic will scale to a much more complex software that
> is wrote for realtime safety critical systems.. but in C++ and C you
> can not do that,
Oh, it's easy to make a range-checked type, for safety, in C++.
In contrast, it's difficult or practically impossible to make a
not-range-checked type, for efficiency, in Pascal.
C#, as a more modern language, has an IMHO better approach where you can
turn off or on range checking via its `checked` keyword. See <url:
https://msdn.microsoft.com/en-us/library/74b4xzyw.aspx> for details.
> but you can just test for the range of the variables,
> but if the software is more complex and you forgot to test the range of
> some variables and it causes a catastrophe at runtime, that`s not ok!
> but with the technic above in FreePascal, you can catch the exception
> easily and you can try to avoid a catastrophe on the realtime safety
> critical system.
Hm. Did you read up on the Ariane failure, as I advised you to?
> This is why C and C++ are bad.
That does not follow from the above.
> Thank you for your time.
No problem, glad to help. ;-)
Cheers,
- Alf