Forum > General

[SOLVED] $STOP directive with value taken from SizeOf

<< < (2/5) > >>

PascalDragon:

--- Quote from: 440bx on May 08, 2021, 02:37:12 am ---A page that documents all the functions that can be used in compiler directive expressions would be very nice.  If you happen to know of one, please do share.

--- End quote ---

How about this one? ;) (Though the arithmetic operators aren't documented (essentially the whole set is supported), so for those a bug report should be filed)

furious programming:
@PascalDragon: useful link, thanks. But can you answer my question? Is it possible to format the content of the error message?

MarkMLl:

--- Quote from: furious programming on May 08, 2021, 06:41:12 pm ---@PascalDragon: useful link, thanks. But can you answer my question? Is it possible to format the content of the error message?

--- End quote ---

I don't think that will do what you want. I'm similarly paranoid about such things, but put them into assertions in the startup code where one /can/ get (and display) an unambiguous actual size.

Otherwise I suggest writing a cut-down test program which is compiled and run as part of the build sequence, i.e. very much like the traditional ./configure scripts would do on a unix platform.

MarkMLl

Remy Lebeau:

--- Quote from: furious programming on May 08, 2021, 02:18:06 am ---Is there any way to use SIZEOF and use the received value to format the message body?

--- End quote ---

No, because {$STOP} does not allow formatted messages.  You would have to check each size individually and {$STOP} a different message for each one, eg:


--- 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";}};} ---type  TMyType = OtherUnit.OtherType;   {$IF SIZEOF(TMyType) <> 1}    {$IF SIZEOF(TMyType) = 2}      {$STOP the size of the TMyType is 2 bytes, but must be 1 byte}    {$ELSEIF SIZEOF(TMyType) = 4}      {$STOP the size of the TMyType is 4 bytes, but must be 1 byte}    ...    {$ELSE}      {$STOP the size of the TMyType is > 1 byte, but must be 1 byte}    {$ENDIF}  {$ENDIF}
Needless to say, that is very verbose coding.  Probably not worth the effort.

440bx:

--- Quote from: PascalDragon on May 08, 2021, 03:49:38 pm ---How about this one? ;) (Though the arithmetic operators aren't documented (essentially the whole set is supported), so for those a bug report should be filed)

--- End quote ---
That is really nice, thank you.  I have to say, not an easy page to find. 

Also, I have not been able to find an "equivalent" in the FPC (pdf) documentation.

Thank you again, that is really useful.

Navigation

[0] Message Index

[#] Next page

[*] Previous page

Go to full version