www.digitalmars.com         C & C++   DMDScript  

D - bug (static function pointer) ?

reply "Dario" <supdar yahoo.com> writes:
int main()
{
    static void (*fp)() = &func;
    fp();
    return 0;
}
void func() {}

This will crash the compiler (v. 0.35).
Is this a known bug? Isn't this code correct?
Jul 24 2002
next sibling parent "anderson" <anderson firestar.com.au> writes:
Defiantly a complier bug. I tested the same code. Anyhow, is static talking
about the function pointer or the type of function (ie static function)?

"Dario" <supdar yahoo.com> wrote in message
news:ahls95$29b1$1 digitaldaemon.com...
 int main()
 {
     static void (*fp)() = &func;
     fp();
     return 0;
 }
 void func() {}

 This will crash the compiler (v. 0.35).
 Is this a known bug? Isn't this code correct?

Jul 24 2002
prev sibling parent Pavel Minayev <evilone omen.ru> writes:
On Wed, 24 Jul 2002 11:41:05 +0200 "Dario" <supdar yahoo.com> wrote:

 int main()
 {
     static void (*fp)() = &func;
     fp();
     return 0;
 }
 void func() {}
 
 This will crash the compiler (v. 0.35).
 Is this a known bug? Isn't this code correct?

It is definitely a bug, and it is even worse: the compiler crashes every time a function pointer is found where a constant expression is expected - which includes initializers for global and static variables.
Jul 24 2002