Skip to content
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

const attribute is removed from parameter of a function pointer #32

Open
joakim-noah opened this issue Aug 23, 2014 · 9 comments
Open

Comments

@joakim-noah
Copy link

I ran into this when translating the following:

typedef void (*AStorageManager_obbCallbackFunc)(const char* filename, const int32_t state, void* data);

DStep turned it into this, removing the const for the second parameter:

alias void function (const(char)*, int, void*) AStorageManager_obbCallbackFunc;

I haven't checked to see if dmd will actually complain about this, but it strikes me as a bug.

@jacob-carlborg
Copy link
Owner

DStep turned it into this, removing the const for the second parameter

This looks a bit odd. But according to libclang, which DStep uses under the hood, state is not const.

I haven't checked to see if dmd will actually complain about this

Why would DMD complain about this?

@jacob-carlborg
Copy link
Owner

Hmm, if I remove the typedef, i.e. during it into a variable declaration, libclang will see it as const.

@jacob-carlborg
Copy link
Owner

I've asked about this on the Clang mailing list.

@joakim-noah
Copy link
Author

Why would DMD complain about this?

Because the callback signature doesn't match the C library? I've had that happen in other situations, not sure if it would here. If you mean that it's the linker that normally catches stuff like this, sure.

Hmm, if I remove the typedef, i.e. during it into a variable declaration, libclang will see it as const.

Yeah, if you turn it into an actual function declaration, it sees the parameter as const, just not when it's a function pointer.

@jacob-carlborg
Copy link
Owner

Because the callback signature doesn't match the C library? I've had that happen in other situations, not sure if it would here. If you mean that it's the linker that normally catches stuff like this, sure.

Right, when you use the function pointer. Yes, then DMD will complain.

Yeah, if you turn it into an actual function declaration, it sees the parameter as const, just not when it's a function pointer.

It's not the function pointer that is the problem, it's the typedef.

@jacob-carlborg
Copy link
Owner

I got a reply [1] from the mailing list and this is apparently how C behaves. I'm not sure that I can do anything about it.

[1] http://clang-developers.42468.n3.nabble.com/const-stripped-in-typedefs-for-parameters-of-primitive-type-td4041337.html

@jacob-carlborg
Copy link
Owner

Perhaps D should allow the callbacks anyway since const doesn't really matter for value types.

@joakim-noah
Copy link
Author

I have no real inclination on what to do here, I wasn't even sure it was a bug. I just reported it as I was double-checking the translation and it seemed like it might be.

@jacob-carlborg
Copy link
Owner

It behaves as it should according to C. But that will cause problems on the D side. I really, really don't want to parse C code without the help of Clang.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants