Recent

Author Topic: "un"def Types  (Read 1266 times)

paule32

  • Full Member
  • ***
  • Posts: 187
"un"def Types
« on: December 21, 2022, 12:14:03 pm »
Hello,

is it possible to "un"def given Types ?
I would try to compile a system.pas unit, and the fpc compiler tells me,
that SmallInt is dupplicated.

Here is the line:
type Smallint = -32768..32767;

How can I "un"def SmallInt, if exists, and when yes, then re-type it.

Thanks for reading

PascalDragon

  • Hero Member
  • *****
  • Posts: 5462
  • Compiler Developer
Re: "un"def Types
« Reply #1 on: December 22, 2022, 07:45:38 am »
You can't because SmallInt is an internal type provided by the compiler itself.

Thaddy

  • Hero Member
  • *****
  • Posts: 14363
  • Sensorship about opinions does not belong here.
Re: "un"def Types
« Reply #2 on: December 22, 2022, 08:05:32 am »
What is your purpose?
Object Pascal programmers should get rid of their "component fetish" especially with the non-visuals.

Leledumbo

  • Hero Member
  • *****
  • Posts: 8757
  • Programming + Glam Metal + Tae Kwon Do = Me
Re: "un"def Types
« Reply #3 on: December 30, 2022, 04:17:16 am »
Not for system unit. Elsewhere, you can override it while still referring to the system unit one by fully qualified name. The compiler has internal type definitions (about 8 or so) that cannot be changed without changing the compiler (system unit alone is not enough).

circular

  • Hero Member
  • *****
  • Posts: 4217
    • Personal webpage
Re: "un"def Types
« Reply #4 on: January 14, 2023, 08:19:42 am »
You could redefine the type so that it cannot be used.

Code: Pascal  [Select][+][-]
  1. type Smallint = record end;
  2.  
  3. var a: Smallint;
  4.  
  5. begin
  6.   a := 3; // compile time error
  7. end;
Conscience is the debugger of the mind

Thaddy

  • Hero Member
  • *****
  • Posts: 14363
  • Sensorship about opinions does not belong here.
Re: "un"def Types
« Reply #5 on: January 14, 2023, 09:28:24 am »
You could redefine the type so that it cannot be used.
Yes, anywhere BUT the system unit!
Everything for which the compiler inserts code is in system.fpd. None of that can be controlled by you unless you rewrite the compiler. Examine rtl\inc\system.fpd for what you can't do yourself.
Note changing the fpd file does not help, it is documentation only. See the header:'This File contains extra, phony declarations used in fpdoc"

Btw, it is still not clear to me how OP wants to redefine the smallint type. There may be other ways to introduce a type with a different range.

The best thing I could come up with is ranges by significant bits in power of two's:
ranges:
2              range  Boolean;
4              range -2..1
8              range -4..3
16            range -8..7
32            range -16..15
64            range -32..31
128          range -64..63
256          range  shortint
512          range -256..255
1024        range -512..511
2048        range -1024..1023
4096        range -2048..2047
8192        range -4096..4095
16384      range -8096..8095
32768      range -16384..16383   
65536      range SmallInt

Well, if I am right, invent some names for the types and write a full set of operators for them....
Like I did for ternary values -1..1.

« Last Edit: January 14, 2023, 05:49:25 pm by Thaddy »
Object Pascal programmers should get rid of their "component fetish" especially with the non-visuals.

VisualLab

  • Sr. Member
  • ****
  • Posts: 310
Re: "un"def Types
« Reply #6 on: January 15, 2023, 08:35:30 pm »
Like I did for ternary values -1..1.

Did it have to do with the TValueSign type?

 

TinyPortal © 2005-2018