Recent

Author Topic: How to resolve "Conversion between ordinals and pointers"  (Read 7414 times)

Zaher

  • Hero Member
  • *****
  • Posts: 571
    • parmaja.com
How to resolve "Conversion between ordinals and pointers"
« on: January 01, 2016, 10:19:21 pm »
This lines give me warning
Code: [Select]
function RangeToProcessor(Range: Pointer): Byte;
begin
  Result := PtrUInt(Range); <----
end;     

Error:
Hint: Conversion between ordinals and pointers is not portable

How to make it portable?
I want to take my byte from that pointer, that i save it before in another function.

there is another problem but in linux only, windows works fine

Code: [Select]

  TRangeState = (rsUnknown, rsComment, rsString);

  FRange: TRangeState;

function TSynFirebirdSyn.GetRange: Pointer;
begin
  Result := Pointer(FRange);
end;

Error:
   Illegal type conversion: "TRangeState" to "Pointer"

Thanks in advance

EDIT:
removed " and $FF"
« Last Edit: January 01, 2016, 11:38:47 pm by Zaher »

eny

  • Hero Member
  • *****
  • Posts: 1587
Re: How to resolve "Conversion between ordinals and pointers"
« Reply #1 on: January 01, 2016, 10:46:27 pm »
Code: Pascal  [Select]
  1. PtrUInt(Range)^ and $FF
?
All posts based on: Win10 (Win64); Lazarus 1.8.0 'stable' (#56594 win64) unless specified otherwise...

Zaher

  • Hero Member
  • *****
  • Posts: 571
    • parmaja.com
Re: How to resolve "Conversion between ordinals and pointers"
« Reply #2 on: January 01, 2016, 11:04:06 pm »
No that not work, i want just type casting.

Zaher

  • Hero Member
  • *****
  • Posts: 571
    • parmaja.com
Re: How to resolve "Conversion between ordinals and pointers"
« Reply #3 on: January 01, 2016, 11:04:56 pm »
The second problem i fixed it like this

Result := Pointer(PtrUInt(FRange));

eny

  • Hero Member
  • *****
  • Posts: 1587
Re: How to resolve "Conversion between ordinals and pointers"
« Reply #4 on: January 01, 2016, 11:14:15 pm »
No that not work, i want just type casting.
Why do you want to 'and'  a pointer with $FF?
All posts based on: Win10 (Win64); Lazarus 1.8.0 'stable' (#56594 win64) unless specified otherwise...

Zaher

  • Hero Member
  • *****
  • Posts: 571
    • parmaja.com
Re: How to resolve "Conversion between ordinals and pointers"
« Reply #5 on: January 01, 2016, 11:16:19 pm »
idk, but without it also i have the same hint

Result := PtrUInt(Range);

eny

  • Hero Member
  • *****
  • Posts: 1587
All posts based on: Win10 (Win64); Lazarus 1.8.0 'stable' (#56594 win64) unless specified otherwise...

Zaher

  • Hero Member
  • *****
  • Posts: 571
    • parmaja.com
Re: How to resolve "Conversion between ordinals and pointers"
« Reply #7 on: January 01, 2016, 11:39:14 pm »
I Edited my question, removed " and $FF"

eny

  • Hero Member
  • *****
  • Posts: 1587
Re: How to resolve "Conversion between ordinals and pointers"
« Reply #8 on: January 02, 2016, 12:34:04 am »
Code: Pascal  [Select]
  1. Result := Byte(Range^)

Off topic: I wonder what brilliant mind invented the name 'PtrUInt' and defined it as an integer type instead of a pointer type %). I guess it's a Delphi thing...
« Last Edit: January 02, 2016, 12:39:27 am by eny »
All posts based on: Win10 (Win64); Lazarus 1.8.0 'stable' (#56594 win64) unless specified otherwise...

taazz

  • Hero Member
  • *****
  • Posts: 5363
Re: How to resolve "Conversion between ordinals and pointers"
« Reply #9 on: January 02, 2016, 01:02:44 am »
Code: Pascal  [Select]
  1. Result := Byte(Range^)

Off topic: I wonder what brilliant mind invented the name 'PtrUInt' and defined it as an integer type instead of a pointer type %) . I guess it's a Delphi thing...
No its a size thing. PtrUint is a pointer sized unsigned integer. Instead of writing code like this
Code: Pascal  [Select]
  1. {$IFDEF CPU32}
  2.   REsult := DWord(Mypointer);
  3. {$ENDIF}
  4. {$IFDEF CPU64}
  5.   REsult := QWord(Mypointer);
  6. {$ENDIF}
  7. {$IFDEF CPU16}
  8.   REsult := Word(Mypointer);
  9. {$ENDIF}
  10. {$IFDEF CPU8}
  11.   REsult := byte(Mypointer);
  12. {$ENDIF}
  13.  
you write this
Code: Pascal  [Select]
  1.   Result := ptruint(MyPointer)
  2.  
and you can be certain that ptruint has the correct size to hold a pointer for your casting.
Good judgement is the result of experience … Experience is the result of bad judgement.

OS : Windows 7 64 bit
Laz: Lazarus 1.4.4 FPC 2.6.4 i386-win32-win32/win64

marcov

  • Global Moderator
  • Hero Member
  • *****
  • Posts: 7495
Re: How to resolve "Conversion between ordinals and pointers"
« Reply #10 on: January 02, 2016, 01:06:33 am »
Code: Pascal  [Select]
  1. Result := Byte(Range^)

Off topic: I wonder what brilliant mind invented the name 'PtrUInt' and defined it as an integer type instead of a pointer type %). I guess it's a Delphi thing...

No, FPC was first with that (went 64-bit a decade before Delphi)

 Delphi of course in all their splendour thought that is totally wrong, and went for uintptr : http://docwiki.embarcadero.com/Libraries/XE8/en/System.UIntPtr

shobits1

  • Sr. Member
  • ****
  • Posts: 278
  • .
Re: How to resolve "Conversion between ordinals and pointers"
« Reply #11 on: January 02, 2016, 01:20:12 am »
Code: Pascal  [Select]
  1. Result := Byte(Range^)

Off topic: I wonder what brilliant mind invented the name 'PtrUInt' and defined it as an integer type instead of a pointer type %). I guess it's a Delphi thing...
Its already well explained in freepascal wiki here : http://wiki.freepascal.org/Multiplatform_Programming_Guide#Pointer_.2F_Integer_Typecasts
and as marcov said, freepascal was the first to introduce a 64-bit compiler.

Abelisto

  • Jr. Member
  • **
  • Posts: 81
Re: How to resolve "Conversion between ordinals and pointers"
« Reply #12 on: January 02, 2016, 01:36:15 am »
The best way as I think

Did you have account at the Facebook? Y/n

And if 'Yes' then "You are too simple to use our service."

Thats all!
OS: Linux Mint + MATE, Compiler: FPC trunk (yes, I am risky!), IDE: Lazarus trunk

Basile-B

  • Sr. Member
  • ****
  • Posts: 457
    • GH...
Re: How to resolve "Conversion between ordinals and pointers"
« Reply #13 on: January 02, 2016, 09:29:20 am »
Code: Pascal  [Select]
  1. Result := Byte(Range^)

Off topic: I wonder what brilliant mind invented the name 'PtrUInt' and defined it as an integer type instead of a pointer type %). I guess it's a Delphi thing...
IIRC Delphi uses more NativeInt and NativeUint, as they were introduced in XE2. The basic problem is that a good name for this quickly becomes too verbose.
Personnaly I think that SystemInt would had been a better choice since that's even not the hardware that defines this. Native is ambiguous. Many of us have used a 64 bit processor for years with a 32 bit Windows...(10 years ago when the first C2D came out, they supported amd 64 but nobody used the Win 64 bit edition).

Basile-B

  • Sr. Member
  • ****
  • Posts: 457
    • GH...
Re: How to resolve "Conversion between ordinals and pointers"
« Reply #14 on: January 02, 2016, 09:32:18 am »
If you're sure of what you're doing just surround the code with:
Code: Pascal  [Select]
  1. {$HINTS OFF}{$WARNINGS OFF}
  2. (**)
  3. {$HINTS ON}{$WARNINGS ON}