On 05/05/12 12:10, Manu wrote: > On 5 May 2012 09:09, Artur Skawina <art.08...@gmail.com > <mailto:art.08...@gmail.com>> wrote: > > On 05/05/12 01:32, Manu wrote: > > On 4 May 2012 21:51, Artur Skawina <art.08...@gmail.com > <mailto:art.08...@gmail.com> <mailto:art.08...@gmail.com > <mailto:art.08...@gmail.com>>> wrote: > > > > On 05/04/12 15:57, Manu wrote: > > > Yeah I really hate this too. I'd like to see const(T) strictly > enforced, considering the potential for ambiguity in other situations. > > > > > > But I'm still stuck! :( > > > How can I do what I need to do? > > > > If 'auto' is not an option: > > > > alias ref const(S) function() FT; > > FT fp; > > > > (it's needed for things like 'extern (C)' too) > > > > > > Huzzah! This is indeed the solution! I haven't seen another solution > that works. now I just need to make sure I generate a unique name for the > alias... > > > > I don't think this is needed for extern (C), I declare extern (C) > function pointers all the time without any trick..? > > void f(extern (C) int function(double) a);
The compiler won't directly accept "void f(extern (C) int function(double) a)" when declaring or defining the function, so the extra alias step is necessary, like in your 'ref' case. > Hmm, actually, this makes me question my code... > > struct Thing > { > extern (C) void function() funcPtr; > } > > Have I declared a pointer to an extern(C) function, or have I declared an > extern(C) variable funcPtr that is a regular D-call function? > extern(C) variables only really make sense in the global scope, where they > would have C-style name mangling applied... alias extern (C) void function() F; F f1; extern (C) F f2; 'f1' is a D pointer a C function, 'f2' is a C pointer to C function (ie f2's name isn't mangled). extern (C) void function() f3; f3 is a C pointer to C function (think 'extern (C) { void function() f3; }'). alias void function() DF; extern (C) DF f4; f4 is a C pointer to a D function. I'd stick to the alias method for every case where the difference actually matters... artur