Forum > General

Hint: Conversion between ordinals and pointers is not portable

(1/4) > >>

440bx:
Hello,

I understand _some_ of the cases when the compiler issues the hint (in the thread title), but there is at least one case where it does not seem to be applicable, specifically, in the case:
--- Code: Pascal  [+][-]window.onload = function(){var x1 = document.getElementById("main_content_section"); if (x1) { var x = document.getElementsByClassName("geshi");for (var i = 0; i < x.length; i++) { x[i].style.maxHeight='none'; x[i].style.height = Math.min(x[i].clientHeight+15,306)+'px'; x[i].style.resize = "vertical";}};} ---if ptruint(SomePointer) = ptruint(0) then ...In that case, ptruint is guaranteed (?) by the compiler to be an unsigned integer of the size of a pointer regardless of platform, therefore, it seems the hint in that case is not applicable since that statement should be portable.

Am I missing something here ?

Thank you for your help.

KodeZwerg:

--- Quote from: 440bx on September 09, 2022, 03:05:14 am ---it seems the hint in that case is not applicable since that statement should be portable.
--- End quote ---
I do full agree, this message should be either more specific (not portable to where?) or not shown at all.

MarkMLl:

--- Quote from: 440bx on September 09, 2022, 03:05:14 am ---
--- Code: Pascal  [+][-]window.onload = function(){var x1 = document.getElementById("main_content_section"); if (x1) { var x = document.getElementsByClassName("geshi");for (var i = 0; i < x.length; i++) { x[i].style.maxHeight='none'; x[i].style.height = Math.min(x[i].clientHeight+15,306)+'px'; x[i].style.resize = "vertical";}};} ---if ptruint(SomePointer) = ptruint(0) then ...
--- End quote ---

You need to show the EXACT error message, and investigate PRECISELY where in the statement to problem is.

Your use of ptruint(SomePointer) suggests that ptruint is happy casting a pointer. But in your second ptruint() the parameter is zero, and my suspicion is that internally it's casting this to nil before applying the explicit cast.

So what the compiler's objecting to is your implicit conversion between zero and nil, not your explicit casts.

MarkMLl

440bx:

--- Quote from: MarkMLl on September 09, 2022, 08:37:07 am ---You need to show the EXACT error message, and investigate PRECISELY where in the statement to problem is.

--- End quote ---
the EXACT error message is in the title of the thread.  As far the "PRECISELY" goes, there is only one place where a conversion from pointer to ordinal occurs, that settles the precision concern.


--- Quote from: MarkMLl on September 09, 2022, 08:37:07 am ---Your use of ptruint(SomePointer) suggests that ptruint is happy casting a pointer.

--- End quote ---
No, on the contrary, the message "suggests" it is not happy at all about that.


--- Quote from: MarkMLl on September 09, 2022, 08:37:07 am ---But in your second ptruint() the parameter is zero, and my suspicion is that internally it's casting this to nil before applying the explicit cast.

--- End quote ---
IF the compiler is internally casting the zero to nil then it is hallucinating because there is no reason to cast the zero to nil and then cast that back to ptruint.  The compiler is most definitely _not_ doing that.


--- Quote from: MarkMLl on September 09, 2022, 08:37:07 am ---So what the compiler's objecting to is your implicit conversion between zero and nil, not your explicit casts.

--- End quote ---
No, it is not complaining about that and there is no implicit conversion of zero to nil in that statement.  That statement, unnecessarily, casts zero to ptruint (which causes no harm and is totally superfluous.)  If you need to convince yourself, remove the ptruint cast of zero and you'll see the same "hint" come up.


--- Code: Pascal  [+][-]window.onload = function(){var x1 = document.getElementById("main_content_section"); if (x1) { var x = document.getElementsByClassName("geshi");for (var i = 0; i < x.length; i++) { x[i].style.maxHeight='none'; x[i].style.height = Math.min(x[i].clientHeight+15,306)+'px'; x[i].style.resize = "vertical";}};} ---{$APPTYPE CONSOLE} program ConversionHint; var  Somepointer : pointer; begin  SomePointer := @Somepointer;  { remove "doesn't seem to be initialized..."  }   if ptruint(SomePointer) = ptruint(0) thenend.              

MarkMLl:

--- Quote from: 440bx on September 09, 2022, 08:55:24 am ---the EXACT error message is in the title of the thread.  As far the "PRECISELY" goes, there is only one place where a conversion from pointer to ordinal occurs, that settles the precision concern.

--- End quote ---

(a) FPC outputs a line and character position for an error message. (b) The error you've quoted is for a conversion between an ordinal and pointer, not a pointer and ordinal.

Using 3.2.2 I can't compile it on Linux without removing that apptype, and when I do there's no error.

MarkMLl

Navigation

[0] Message Index

[#] Next page

Go to full version