[Issue 3797] New: Function pointers need to be stricter
d-bugmail at puremagic.com
d-bugmail at puremagic.com
Fri Feb 12 05:34:09 PST 2010
http://d.puremagic.com/issues/show_bug.cgi?id=3797
Summary: Function pointers need to be stricter
Product: D
Version: 2.040
Platform: All
OS/Version: All
Status: NEW
Severity: enhancement
Priority: P2
Component: DMD
AssignedTo: nobody at puremagic.com
ReportedBy: yebblies at gmail.com
--- Comment #0 from yebblies <yebblies at gmail.com> 2010-02-12 05:34:08 PST ---
Currently functions pointers can be implicitly converted despite having
different calling conventions. If at all possible, function pointers should
require a cast to change calling convention.
In a related problem, it is possible to implicitly convert function pointers
with different argument lists.
The following code compiles but segfaults (Access Violation) on dmd 2.040 /
winxp.
import std.stdio;
void foo(real f)
{
writeln("bar ", f);
}
void main()
{
void function(ubyte[4]) ptr1 = &foo;
extern(C) void function(long, long) ptr2 = ptr1;
ptr1([0xFF, 0xFF, 0xFF, 0xFF]);
ptr2(3, 8);
}
Function pointers cannot, however, be cast to a pointer with a different return
type.
To solve this problem: Disable all implicit conversions between function
pointers, requiring function parameters, return type, and calling convention to
match for assignment copying. This prevents accidental conversions and allows
template code to be aware of the correct calling convention.
--
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