[fpc-pascal] Re: Get all caller adresses of a given function/procedure before executing

Jorge Aldo G. de F. Junior jagfj80 at gmail.com
Tue Aug 14 23:43:23 CEST 2012


Why not scan the code with passrc, find the strings, build a table and
then replace the strings with calls to a function that does the
translation ?

your hack sounds like a maintenance nightmare... Thats what a C
programmer would do and then boast about his programming skills, just
to later discovar that his solution is nor portable nor safe...

2012/8/14 Rainer Stratmann <RainerStratmann at t-online.de>:
> Am Tuesday 14 August 2012 14:36:44 schrieb Martin:
>> On 14/08/2012 13:19, Rainer Stratmann wrote:
>> > It was more or less exactly the way I did it before with little
>> > exaggerating as you notice :-)
>> > Even now I save 50% codesize in comparison to resourcestring.
>>
>> If you don't like resource string, inho there are 2 alternatives that
>> are (IMHO) better:
>>
>> 1)
>> plain array with all text constants. You can break it into one array per
>> unit, and have a register a search-handler via the unit's initialization.
>>
>> const MySnippets: Array [1..xxx] of string = ('text', '...', ... ];
>>
>> For more readability (but it adds source code (should not add more to exe)
>>
>> const
>>     snip1: 'text';
>>    MySnippets: Array [1..xxx] of string = (snip1, '...', ... ];
>>
>> (actually, I havent testet if the compiler takes the 2nd
>
> Then you have to put _all_ text snippets at once there (!)
> I didn't count my text snippets in this project, but they are spread over
> about more than 10 units.
>
>> 2)
>> Since you seem to want something that is easier to type.
>>
>> Keep using
>>    writeln(ls('text'));
>>
>> Instead of analysing the exe, write your own pre-precessor.
>
> I considered this, but the solution now is - in my view - unbeatably easy.
> And that is what counts for me.
>
>> The pre-processor can scan the source, create a temporary copy in which
>> it replaces the text in ls() with a reference to the "MySnippets[]" array.
>> It also creates and includes a unit with that array.
>> It then calls the compiler on the temporary created sources....
>>
>> At least it will keep working even if fpc internals change.
>
> I do not worry about this. The search procedure can easily adapted then.
>
>> And it is cross platform (includes cross-CPU)
>
> Yes, that's true. But I am confident to find here also a solution once it will
> be necessary.
> _______________________________________________
> 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