[fpc-devel] constref in Windows

José Mejuto joshyfun at gmail.com
Fri Nov 19 14:36:21 CET 2010

Hello Joost,

Friday, November 19, 2010, 1:02:59 PM, you wrote:

JvdS> Well, this issue leaded to a large discussion elsewhere. I was wondering
JvdS> when someone else would even notice this incompatibility. A lot of
JvdS> alternatives have been discussed, but I coud not find any which is less
JvdS> intrusive.

I had followed the discussion in the public lists but not in the
development internal lists.

JvdS> In an nutshell: the behavior of 'const' parameters is undefined. When
JvdS> using cdecl the 'const' keyword is simply ignored. But we do need to
JvdS> pass the GUID by reference.

I'm aware...

JvdS> There are two options:
JvdS> 1: Change the behavior of const-parameters. That can lead to
JvdS> unpredictable problems which are not noticed by the compiler. It could
JvdS> be an option to use some setting to define the behavior of 'const', but
JvdS> in that case that setting have to be set for all units that do a call to
JvdS> QueryInterface. (ie: all code using interfaces, so it means this setting
JvdS> has to be set everywhere where COM code is used)

Currently Win32 (only win32) could work with const in that interface,
taking in account that any other interface functions in IUnknown
descendents will be mostly typed with const instead constref, so
people with interfaces will inadvertly have const everywhere but
QueryInterface. Anyway, continue reading...

JvdS> 2: Change the definition to constref, so the compiler will complain if a
JvdS> user override the QueryInterface's definition, and can adapt the code.

This is the best, of course, but is there any possibility to fine tune
the message error in that case to offer the solution to the programmer
directly ? Can a special error message be emited for this error in
QueryInterface ?

JvdS> Notice that until now I've only heard of code which overrides
JvdS> QueryInterface in the Free Pascal code itself, in the Lazarus code, ZEOS
JvdS> and the code from one commercial developer who also works on
JvdS> Lazarus/Free Pascal.
JvdS> It is an incompatibility, yes. But I think it's not too intrusive and I
JvdS> see no alternatives...

No, not intrusive, but very hard to find the solution for average joe,
in fact I had solved it in my Zeos just after seen the "error" but
most people are not aware of the change. I'm looking for a help in
solution, not an interface change.

Best regards,

More information about the fpc-devel mailing list