[fpc-devel] Proposal: Supporting initial references for weakexternal

Jonas Maebe jonas.maebe at elis.ugent.be
Wed Jan 12 23:18:09 CET 2011


On 12 Jan 2011, at 22:54, Jeppe Johansen wrote:

> Den 12-01-2011 20:47, Jonas Maebe skrev:
>> I can't immediately think of a good syntax to directly define MyIRQHandler as a weak symbol with the address of NoHandler as default value. Maybe this, although I'm not 100% happy with it either:
>> 
>>    procedure MyIRQHandler; weak 'NoHandler';
> Maybe something like instead? Requiring a symbol reference to a matching implementation of a default value, like Paul suggested, would make the solution more Pascal-like
> 
>  procedure NoHandler;
>    begin
>      { dummy implementation }
>    end;
> 
>  { Declaration NoHandler must exist and match }
>  procedure MyIRQHandler; weak NoHandler;

The type checking will have to be delayed, since you can only compare the procdef types after the entire second declaration has been parsed (there could e.g. still be calling convention modifiers after that).

>  { This will emit just a weak reference, the same as weakexternal; Not guaranteed to be resolved after compiletime }
>  procedure MyIRQHandler2; weak;
> 
> This of course just introduces a new keyword weak, which was why I tried to base it off the weakexternal keyword

This second example cannot be the same as "weakexternal". Just like a regular "external" declaration does not generate any data, code or reference by itself, a "weakexternal" declaration does not do so either. external/weakexternal are simply Pascal-level aliases that can be used to refer to non-Pascal external symbols, a bit like "absolute" can be used for Pascal symbols.

I don't think that "procedure MyIRQHandler2; weak;" without any implementation should be allowed. It would create a weak symbol in the middle of nowhere, not associated with any particular code or data (and hence probably merged by the linker with the next symbol in the section). It would be the same as allowing "procedure MyIRQHandler2;" without any code or "(weak)external".



Jonas


More information about the fpc-devel mailing list