[fpc-pascal] Get all caller adresses of a procedure/function

Aleksa Todorovic alexione at gmail.com
Mon Aug 6 22:37:08 CEST 2012

On Mon, Aug 6, 2012 at 9:48 PM, Rainer Stratmann
<RainerStratmann at t-online.de> wrote:
> Am Monday 06 August 2012 21:26:24 schrieb Jonas Maebe:
>> It doesn't work like that. Regular calls use relative offsets on most (if
>> not all) architectures we support. And in some cases we generate
>> position-independent code, so then you'll have look at GOT entries to
>> figure out the address. Then there are of course calls via procedure
>> variables. And there's probably a ton more special cases I'm not thinking
>> of right now.
> Would it then be possible to implement a counter (const) which is increased at
> compile time?
> p1( increasedcounteratcompiletime , 'Textsnippet' ) ?
> I guess it is not possible.
>> >> Out of curiosity: why don't you use resourcestrings?
>> >
>> > It seems that is has not the flexibility and simplicity (in its entirety)
>> > that I want.
>> I would not call your method "simple"
> It may is in the beginning more difficult to implement, but if it runs once I
> would say this can not get much more simpler.
> You only have to put p1( ) around your text snippet. That is it!
> The function returns the right language.
>> and would also strongly recommend to
>> use resourcestrings instead. Their purpose is exactly to make it easy to
>> translate the strings in a program.
> That means more work to give every text snippet explicitly a name which is not
> necessary with my solution. And that means also less flexibility.
> The resourcestring solution does not record the date and time when a text was
> changed and so on...

How about using memory for string constant to store pointer to
localized version - something like example below? Note: target
platform needs to support writable string constants, and there should
be enought ~ characters at the beginning of the string to store value
of pointer (4x~ for 32-bit pointers, 8x~ for 64bit pointers). If you
can meet these two conditions, you don't need to know internals of
compiler or any implementation detail.

program test_str_36;


function s(str: pchar): pchar;
  str2: pchar;
  if str[0] = '~' then
    // string is not localized
    str2 := strnew('numero'); // localized version
    ppchar(str)^ := str2;
  result := ppchar(str)^;

  i: integer;
  for i := 1 to 10 do
    writeln(s('~~~~~~~~number'), ' ', i);

> _______________________________________________
> fpc-pascal maillist  -  fpc-pascal at lists.freepascal.org
> http://lists.freepascal.org/mailman/listinfo/fpc-pascal

More information about the fpc-pascal mailing list