Re: HEEELP CRgn copy?

Tech-Archive recommends: Fix windows errors by optimizing your registry

From: Joseph M. Newcomer (newcomer_at_flounder.com)
Date: 11/06/04


Date: Sat, 06 Nov 2004 18:22:20 -0500

Yes, this is actually a typical sort of bug that Microsoft has. Even in the case where the
object is not being modified, they forgot to include the 'const' attribute on the
parameter. CopyRgn SHOULD have had 'const' on it, and the fact that it does not is a
mistake. Microsoft has never really understood 'const', and fails to use it where it is
required. They also do things like claim a parameter or return value is a UINT and then
claim that "-1" is a valid return value. But you can't write
        DWORD value = someAPI();
        if(value == -1)
because the compiler rightly complains about a signed vs. unsigned test. This is a common
problem, and of course to maintain backward compatibility, they won't fix the bugs.
                                joe
On Sat, 6 Nov 2004 12:33:56 +0100, "Lisa Pearlson" <no@spam.plz> wrote:

>I have another weird problem.
>
>I am passing my parameters to the constructor and assignment operator as a
>'const' object.
>I then have to cast this back to a non const (CRgn*) to pass it to CopyRgn.
>
>CNamedRgn& operator= (const CNamedRgn& nr) {
> ...
> rgn.CopyRgn((CRgn*)&nr);
> ..
>}
>
>But if I remove the const, so I don't have to cast it in CopyRgn, I actually
>get a compile error:
>
>c:\program files\microsoft visual studio\vc98\mfc\include\afxtempl.h(86) :
>error C2679: binary '=' : no operator defined which takes a right-hand
>operand of type 'const struct tagMapRegion' (or there is no acceptable
>conversion)
> c:\program files\microsoft visual
>studio\vc98\mfc\include\afxtempl.h(406) : see reference to function template
>instantiation 'void __stdcall CopyElements(struct tagMapRegion *,const
>struct tagMapRegion *,int)' being compiled
>
>
>I am not passing a const.. so it seems CopyElements (underlying code to
>CopyRgn I guess) does as shown in the last line above. Yet CopyRgn doesn't
>expect const. Weird?
>
>Lisa
>

Joseph M. Newcomer [MVP]
email: newcomer@flounder.com
Web: http://www.flounder.com
MVP Tips: http://www.flounder.com/mvp_tips.htm



Relevant Pages

  • Re: HEEELP CRgn copy?
    ... Aside from the whole const issue, why do I get an assert here? ... tagMapRegion(): color ... >>But if I remove the const, so I don't have to cast it in CopyRgn, I ...
    (microsoft.public.vc.mfc)
  • Re: HEEELP CRgn copy?
    ... I then have to cast this back to a non const to pass it to CopyRgn. ... I am not passing a const.. ...
    (microsoft.public.vc.mfc)
  • Re: How about this syntactic candy? - The results
    ... and the results are significant performance-wise: ... So, even if "const" never gets adopted, using a temporary variable seems to achieve 2x results. ... Microsoft Visual C# .NET Compiler version 7.10.6001.4 ... The relative gap is rather uninteresting. ...
    (microsoft.public.dotnet.languages.csharp)
  • Re: newbie problem with stored procedure return value
    ... DECLARE @nextOrder integer ... Const adExecuteNoRecords = &H00000080 ... Microsoft MVP -- ASP/ASP.NET ... Please reply to the newsgroup. ...
    (microsoft.public.inetserver.asp.db)
  • Re: Reference counting bug D6
    ... | a) never have interfaces as const parameters or b) use a cast like ... is not a bug, it is as it should be. ... method with a const parameter; therefore there is no reference to increment ...
    (borland.public.delphi.language.objectpascal)