[Issue 3605] Compiler accepts invalid variable declaration, which does not link

d-bugmail at puremagic.com d-bugmail at puremagic.com
Fri Dec 11 03:37:31 PST 2009


http://d.puremagic.com/issues/show_bug.cgi?id=3605



--- Comment #3 from Lars T. Kyllingstad <bugzilla at kyllingen.net> 2009-12-11 03:37:30 PST ---
I will would like to say though, that it shouldn't be possible to declare
functions like this in D. With the module system, I can't see any practical way
of defining a function in a separate .d file, as its name will be mangled with
the module name. Here's an example:

x.d:
   import std.stdio;
   void print(int i) { writeln(i); }

y.d:
  void print(int);
  void main() { print(123); }

$ dmd -c x.d
$ dmd y.d x.o
y.o: In function `_Dmain':
y.d:(.text._Dmain+0x9): undefined reference to `_D1y5printFiZv'
collect2: ld returned 1 exit status
--- errorlevel 1

The declaration in y.d is mangled as _D1y5printFiZv, which means y.print(int),
while the object file will contain _D1x5printFiZv, or x.print(int).

-Lars

-- 
Configure issuemail: http://d.puremagic.com/issues/userprefs.cgi?tab=email
------- You are receiving this mail because: -------


More information about the Digitalmars-d-bugs mailing list