New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

stdcallcc function pointers not allowed in extern structs #1536

Closed
emekoi opened this Issue Sep 17, 2018 · 4 comments

Comments

Projects
None yet
2 participants
@emekoi
Contributor

emekoi commented Sep 17, 2018

is it possible to put function pointers in extern structs? for example

pub const WNDPROC = stdcallcc fn(para1: HWND, para2: UINT, para3: WPARAM, para4: LPARAM)  LRESULT;
  
pub const WNDCLASS = extern struct {
    style: UINT,
    lpfnWndProc: ?WNDPROC,
    cbClsExtra: c_int,
    cbWndExtra: c_int,
    hInstance: HANDLE,
    hIcon: HICON,
    hCursor: HCURSOR,
    hbrBackground: HBRUSH,
    lpszMenuName: [*]const WCHAR,
    lpszClassName: [*]const WCHAR,
};

@emekoi emekoi changed the title from function pointer to function pointers in extern structs Sep 17, 2018

@andrewrk

This comment has been minimized.

Member

andrewrk commented Sep 17, 2018

Should work fine. Are you experiencing a problem?

@emekoi

This comment has been minimized.

Contributor

emekoi commented Sep 17, 2018

is this a recent change? because i get an error when i try to do that.

@andrewrk

This comment has been minimized.

Member

andrewrk commented Sep 17, 2018

I created a test case for you:

use @import("std").os.windows;

pub const WNDPROC = stdcallcc fn (para1: HANDLE, para2: UINT, para3: i32, para4: i32) i32;

pub const WNDCLASS = extern struct {
    style: UINT,
    lpfnWndProc: ?WNDPROC,
    cbClsExtra: c_int,
    cbWndExtra: c_int,
    hInstance: HANDLE,
    hIcon: HANDLE,
    hCursor: HANDLE,
    hbrBackground: HANDLE,
    lpszMenuName: [*]const WCHAR,
    lpszClassName: [*]const WCHAR,
};

test "aoeu" {
    var a: WNDCLASS = undefined;
}

I'm guessing the error message that you're getting is

/home/andy/downloads/zig/build/test.zig:7:5: error: extern structs cannot contain fields of type '?stdcallcc fn(*c_void, c_uint, i32, i32) i32'
    lpfnWndProc: ?WNDPROC,
    ^

This is a bug where zig incorrectly thinks that stdcallcc functions cannot be in extern structs, when in fact they can. It's easy to fix, so I'll prioritize it.

@andrewrk andrewrk added this to the 0.3.0 milestone Sep 17, 2018

@andrewrk andrewrk added the bug label Sep 17, 2018

@andrewrk andrewrk changed the title from function pointers in extern structs to stdcallcc function pointers not allowed in extern structs Sep 17, 2018

@andrewrk andrewrk closed this in 9c9eefc Sep 17, 2018

@emekoi

This comment has been minimized.

Contributor

emekoi commented Sep 17, 2018

thanks!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment