Same here, the compiler assumes that the function i() will be linked in later,
and therefore accepts it. The next line works because of the property syntax
for calling functions. Writing i.max is equivalent to writing i().max. The
property max is available for all ints.

int a = i.max; // surprisingly this and next line works.
writeln (a);

The next line also works because of the property syntax. Writing i=1 is
equivalent to writing i(1).

//i = 1; // uncomment this to cause error
//writeln (i); // or this
}
2b. this example works correctly – compiler gives some error message, even if
not so appropriate.
Error: function main.main.i () is not callable using argument types (int)
Error: expected 0 arguments, not 1 for non-variadic function type int()

This is because the compiler interprets i=1 as i(1), which doesn't work since
you have declared i() without any parameters.

http://d.puremagic.com/issues/show_bug.cgi?id=3605
--- Comment #3 from Lars T. Kyllingstad <bugzilla 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: -------

http://d.puremagic.com/issues/show_bug.cgi?id=3605
--- Comment #4 from Michal Minich <michal.minich gmail.com> 2009-12-11 04:15:06
PST ---
Thank you for explanation Lars,
It did not occurred to me that "int i();" can be function declaration. Maybe if
such declaration required extern(D) attribute, it would be more clear what's
going on. I cannot imagine what is this feature intended to do… Maybe it has
some use in connection with .di files…
--
Configure issuemail: http://d.puremagic.com/issues/userprefs.cgi?tab=email
------- You are receiving this mail because: -------