On 14 Feb 2011, at 14:36, Jeppe Johansen wrote:

Den 14-02-2011 14:00, Jonas Maebe skrev:

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.


Sure, the weak declaration as a procedure directive could be added, and it would indeed be something different from a weakexternal procedure. Weakexternal should stay as it is, a procedure declaration directive. I can see how a "weak" directive could be useful, but I don't need that. I need a linker directive that points to one of two external functions

The reason weakexternal makes sense is because it's a weak undefined symbol reference to some external symbol,

A "weakexternal" declaration by itself is not a reference (weak/ undefined or not), neither at the Pascal, C nor at the assembler/ object file level. It only says that *if* there is a reference to that symbol, then this reference should be treated as a weak reference.

which - if it doesn't exist - points to some other external reference. A weak procedure would be almost the same, you just add the default reference as code explicitly

It's the same as the difference between these two declarations in C:

int SayHello(void) __attribute__((weak))
{
  ...
}

and

extern int SayHello() __attribute__((weak));
or
extern int SayHello() __attribute__((weak,alias 'OtherSayHello'));

(this second "alias" form is not supported by all object formats though -- e.g. gcc on Mac OS X warns that it's ignored --, but at the Pascal level it can be emulated by the compiler just like for non-weak alias definitions)

The problem with weak is that it's tagged onto a piece of code. So in a case like the one that originally provoked the proposal

 procedure EmptyFunc;
   begin // Empty function
   end;

procedure Func1; weakexternal name 'Func1' default 'EmptyFunc';
procedure Func2; weakexternal name 'Func2' default 'EmptyFunc';

using weak you would need two procedures.

No, because you would be able to combine "weak" and "external" to get the same result as with "weakexternal". Furthermore, there's also the "alias" modifier to add symbol aliases to a definition.

I'm also not sure why you made this remark, because at no point I suggested removing the functionality currently offered by "weakexternal". I only proposed to make the syntax more orthogonal, and to extend the semantics of "weakexternal;"/"weak; external;" so that the "default 'xxx'" specifier is not required while still getting the same effect.


Jonas
_______________________________________________
fpc-devel maillist  -  fpc-devel@lists.freepascal.org
http://lists.freepascal.org/mailman/listinfo/fpc-devel

Reply via email to