Recent

Author Topic: Getting and checking language mode  (Read 885 times)

MarkMLl

  • Hero Member
  • *****
  • Posts: 6676
Getting and checking language mode
« on: August 25, 2019, 02:54:58 pm »
I'm revisiting some stuff I wrote a few years ago which puts a form and associated code in a dynamically-linkable library (.so) which can be reloaded on receipt of a HUP signal or if the library has been recompiled (date in the filename). My experience is that my implementation is pretty robust, and I'm reusing it to support a handheld 'scope (https://jyetech.com/dso-coral-112a-oscilloscope/) and possibly for some older stuff with the intention of publishing it somewhere.

I'm confident in my handling of "magic numbers" describing the API presented by both the library and main program, and have a workable way that the library can be compiled statically for debugging without significant code changes. However noting the Dire Warning "it may be that the arguments or return values differ if the library is compiled in 2 different modes" https://www.freepascal.org/docs-html/prog/progse55.html I have to ask:

Is there an easy way to generate a numeric value encoding the compilation mode used for a particular unit, together with any relevant overrides (cdecl etc.)?

MarkMLl
MT+86 & Turbo Pascal v1 on CCP/M-86, multitasking with LAN & graphics in 128Kb.
Pet hate: people who boast about the size and sophistication of their computer.
GitHub repositories: https://github.com/MarkMLl?tab=repositories

Bart

  • Hero Member
  • *****
  • Posts: 5275
    • Bart en Mariska's Webstek
Re: Getting and checking language mode
« Reply #1 on: August 25, 2019, 03:37:44 pm »
If I understand correctly that is about the size of the arguments, which you can check with SizeOf.

Bart

MarkMLl

  • Hero Member
  • *****
  • Posts: 6676
Re: Getting and checking language mode
« Reply #2 on: August 25, 2019, 03:53:24 pm »
True, so in principle and with reference to https://www.freepascal.org/docs-html/current/ref/refsu4.html#x26-250003.1.1 if you avoid woolly terms like "integer" you should be OK. But then there's still the difference between cdecl and pascal, variations in packing behaviour, and so on :-/

OTOH, if the function which returned the magic number used cdecl but was called using the pascal convention things would fall over long before any more detailed checks started to be made. And if packing was wrong the functions which e.g. copied menu items from the library form to the main program would be visibly broken.

But I'm still left feeling a bit uncomfortable since there's a whole lot of stuff which apparently can't be checked using e.g. $ifopt

MarkMLl
MT+86 & Turbo Pascal v1 on CCP/M-86, multitasking with LAN & graphics in 128Kb.
Pet hate: people who boast about the size and sophistication of their computer.
GitHub repositories: https://github.com/MarkMLl?tab=repositories

 

TinyPortal © 2005-2018