Define a primitive data type: Difference between revisions
review →Pascal
(Add a Rust solution) |
(review →Pascal) |
||
Line 191:
===Other libraries or implementation specific extensions===
As of February 2009 no open source libraries to do this task have been located.
=={{header|C sharp|C#}}==
<lang csharp>public struct TinyInt
Line 286 ⟶ 287:
unsigned char value; // we don't need more space
};</lang>
=={{header|Clojure}}==
Line 429 ⟶ 431:
assert(j > i);
}</lang>
=={{header|Delphi}}==
''See [[#Free Pascal|Free Pascal]]''
=={{header|Dyalect}}==
Line 542 ⟶ 548:
❗ error: One-ten : type-check failure : 42 → 'f10:x'
</lang>
=={{header|Elena}}==
ELENA 4.x:
Line 897 ⟶ 904:
i = 10 j = 3 k = 4 j + 6 = 9 j + k = 7
</pre>
=={{header|Free Pascal}}==
''See [[#Pascal|Pascal]]''
<lang pascal>type
range = 1..10;
begin▼
range := 10;
{$rangeChecks on}
range := range + 10; // will yield a run-time error
The FPC (Free Pascal compiler) by default does ''not generate'' range checks.
Assigning a value out of range is possible.
Only constant expressions, i. e. expressions that can be evaluated entirely during compile-time, are not accepted, if they are out of range.
The compiler directive <tt>{$rangeChecks on}</tt> will enable insertion of range checks.
If an out of range assignment is attempted, a run-time error occurs.
Note, in <tt>{$mode Delphi}</tt> range checks are only switchable at procedural level, not on a per expression-basis.
=={{header|Go}}==
Line 1,681 ⟶ 1,706:
=={{header|Pascal}}==
<lang pascal>type
naturalTen = 1..10;</lang>
As per ISO 7185, any (attempted) assignment out of range constitutes an error.
However, the processor (usually a compiler) is permitted to leave such an error undetected.
Modern compilers such as [[#Delphi|Delphi]] and [[#Free Pascal|Free Pascal]] give the programmer a choice, which behavior is desired, by providing compiler switches/directives.
▲begin
▲end.</lang>
=={{header|Perl}}==
|