[fpc-devel] Proposal: Supporting initial references for	weakexternal
    Jonas Maebe 
    jonas.maebe at elis.ugent.be
       
    Mon Feb 14 14:00:38 CET 2011
    
    
  
On 14 Feb 2011, at 13:45, Jeppe Johansen wrote:
> I did a little change to the patch though. I changed the syntax to  
> be "weakexternal ['library'] [name 'name'] [default  
> 'initialvalue'];" since I figured default made more sense than set,  
> in the given context. I still think using weakexternal makes  
> sense(over adding a new "weak" keyword), since the meaning and  
> functionality still is the same
It's not the same.
"weak" (without external) would be a definition, which means that it  
would be used in a situation like this:
   procedure Test; weak;
     begin
       writeln('test');
     end;
And the compiler would then generate something like this:
   .weak Test
Test:
   <code for test>
This would however be invalid code:
   procedure Test; weak; external; // or "weakexternal" instead of  
"weak; external;"
     begin
     end;
And this would be an incomplete declaration (missing function body):
   procedure Test; weak;
That's why it was not a good idea (from me) to introduce  
"weakexternal", since "weak" combined with "external" would be the  
same (even if "weak" by itself weren't supported immediately).  
Furthermore, the whole "default 'initialvalue'" stuff is actually  
superfluous, since it basically is already part of the weak(external)  
declaration:
   procedure Test; weakexternal name 'aliasedTest';
could be defined to generate this:
   .weak Test
   .set Test,aliasedTest
After all, the above states that references to "Test" should be  
treated as weak references to a symbol called "aliasedTest". It would  
also be equivalent to what C does. I also don't think it would break  
much, if any, existing code that uses "weakexternal" if the semantics  
were to be redefined in this way.
Jonas
    
    
More information about the fpc-devel
mailing list