Saturday, April 24, 2021

code analysis tools

code analysis tools

  1. What are the best code visualization and analysis tools?
  2. What are the best code visualization and analysis tools?

  3. A Static Analysis Tool for C++
  4. This article is a user guide to a static analysis tool for C++ code. Among other things, the tool can clean up #include lists, highlight violations of C++ best practices, and analyze dependencies within the code base. It can also implement some of its suggestions by editing the code. The article also provides a high-level overview of the tool's implementation..

  5. What are the best open source C++ static analysis tools?
  6. What are the best open source C++ static analysis tools?.

  7. GitHub project issues
  8. Update: Your site configures GitHub's Webhooks capability to trigger on push events, and it doesn't provide a way to limit this to the master branch. I could change it so that you're notified of branch deletions instead (I delete a side branch after merging it into the master branch) or releases (not something that I currently use, but which might work for others). The appropriate trigger event depends on how a project is administered, but it shouldn't be difficult to get the project owner to tweak it. I'm assuming, however, that GitHub sends you all the information you need, regardless of the trigger event, which may not be the case..

  9. This is a paragraph.

  10. This is a paragraph.

  11. This is a paragraph.

  12. This is a paragraph.

  13. This is a paragraph.

  14. This is a paragraph.

  15. This is a paragraph.

  16. This is a paragraph.

  17. This is a paragraph.

  18. This is a paragraph.

  19. This is a paragraph.

  20. This is a paragraph.

  21. This is a paragraph.

  22. This is a paragraph.

Saturday, April 17, 2021

override , final, virtual (function) keyword

override, final, virtual (function) keyword

    keyword:final

  1. final specifier (since C++11)
  2. Definition: Specifies that a virtual function cannot be overridden in a derived class or that a class cannot be inherited from.

    Usage:

    declarator virt-specifier-seq(optional) pure-specifier(optional) (1)

    declarator virt-specifier-seq(optional) function-body (2)

    class-key attr(optional) class-head-name class-virt-specifier(optional) base-clause(optional) (3)

    1. In a member function declaration, final may appear in virt-specifier-seq immediately after the declarator, and before the pure-specifier, if used.
    2. In a member function definition inside a class definition, final may appear in virt-specifier-seq immediately after the declarator and just before function-body.
    3. In a class definition, final may appear as class-virt-specifier immediately after the name of the class, just before the colon that begins the base-clause, if used.

    In the cases (1,2), virt-specifier-seq, if used, is either override or final, or final override or override final. In the case (3), the only allowed value of class-virt-specifier, if used, is final

    Syntax

    When applied to a member function, the identifier final appears immediately after the declarator in the syntax of a member function declaration or a member function definition inside a class definition.

    When applied to a class, the identifier final appears at the beginning of the class definition, immediately after the name of the class.

    Explanation

    When used in a virtual function declaration or definition, final specifier ensures that the function is virtual and specifies that it may not be overridden by derived classes. The program is ill-formed (a compile-time error is generated) otherwise.

    When used in a class definition, final specifies that this class may not appear in the base-specifier-list of another class definition (in other words, cannot be derived from). The program is ill-formed otherwise (a compile-time error is generated). final can also be used with a union definition, in which case it has no effect (other than on the outcome of std::is_final) (since C++14), since unions cannot be derived from.

    final is an identifier with a special meaning when used in a member function declaration or class head. In other contexts it is not reserved and may be used to name objects and functions.

    keyword:override

  3. override specifier (since C++11)
  4. Definition:Specifies that a virtual function overrides another virtual function..

    Syntax The identifier override, if used, appears immediately after the declarator in the syntax of a member function declaration or a member function definition inside a class definition.

    Usage:

    declarator virt-specifier-seq(optional) pure-specifier(optional) (1)

    declarator virt-specifier-seq(optional) function-body (2)

    1. In a member function declaration, override may appear in virt-specifier-seq immediately after the declarator, and before the pure-specifier, if used.
    2. In a member function definition inside a class definition, override may appear in virt-specifier-seq immediately after the declarator and just before function-body.

    In both cases, virt-specifier-seq, if used, is either override or final, or final override or override final.

    Explanation

    In a member function declaration or definition, override specifier ensures that the function is virtual and is overriding a virtual function from a base class. The program is ill-formed (a compile-time error is generated) if this is not true.

    override is an identifier with a special meaning when used after member function declarators: it's not a reserved keyword otherwise.

    virtual function:

  5. virtual function specifier
  6. Definition:The virtual specifier specifies that a non-static member function is virtual and supports dynamic dispatch. It may only appear in the decl-specifier-seq of the initial declaration of a non-static member function (i.e., when it is declared in the class definition).

    Explanation

    Virtual functions are member functions whose behavior can be overridden in derived classes.

    As opposed to non-virtual functions, the overriding behavior is preserved even if there is no compile-time information about the actual type of the class. That is to say, if a derived class is handled using pointer or reference to the base class, a call to an overridden virtual function would invoke the behavior defined in the derived class. Such a function call is known as virtual function call or virtual call.

    Virtual function call is suppressed if the function is selected using qualified name lookup (that is, if the function's name appears to the right of the scope resolution operator ::).

    In detail

    If some member function vf is declared as virtual in a class Base, and some class Derived, which is derived, directly or indirectly, from Base, has a declaration for member function with the same

    1. name
    2. parameter type list (but not the return type)
    3. cv-qualifiers
    4. ref-qualifiers

    key point: Then this function in the class Derived is also virtual (whether or not the keyword virtual is used in its declaration) and overrides Base::vf (whether or not the word override is used in its declaration).

    key note: Base::vf does not need to be accessible or visible to be overridden. (Base::vf can be declared private, or Base can be inherited using private inheritance. Any members with the same name in a base class of Derived which inherits Base do not matter for override determination, even if they would hide Base::vf during name lookup.)

    key note: For every virtual function, there is the final overrider, which is executed when a virtual function call is made. A virtual member function vf of a base class Base is the final overrider unless the derived class declares or inherits (through multiple inheritance) another function that overrides vf.

    Key Note:A function with the same name but different parameter list does not override the base function of the same name, but hides it: when unqualified name lookup examines the scope of the derived class, the lookup finds the declaration and does not examine the base class.

    Key Note: Non-member functions and static member functions cannot be virtual.

    Key Note: Function templates cannot be declared virtual. This applies only to functions that are themselves templates - a regular member function of a class template can be declared virtual.

    Virtual destructor Even though destructors are not inherited, if a base class declares its destructor virtual, the derived destructor always overrides it. This makes it possible to delete dynamically allocated objects of polymorphic type through pointers to base.

    Moreover, if a class is polymorphic (declares or inherits at least one virtual function), and its destructor is not virtual, deleting it is undefined behavior regardless of whether there are resources that would be leaked if the derived destructor is not invoked.

    A useful guideline is that the destructor of any base class must be public and virtual or protected and non-virtual

    During construction and destruction When a virtual function is called directly or indirectly from a constructor or from a destructor (including during the construction or destruction of the class’s non-static data members, e.g. in a member initializer list), and the object to which the call applies is the object under construction or destruction, the function called is the final overrider in the constructor’s or destructor’s class and not one overriding it in a more-derived class. In other words, during construction or destruction, the more-derived classes do not exist.

    My Note: this example is great and contains knowledge...

    When constructing a complex class with multiple branches, within a constructor that belongs to one branch, polymorphism is restricted to that class and its bases: if it obtains a pointer or reference to a base subobject outside this subhierarchy, and attempts to invoke a virtual function call (e.g. using explicit member access), the behavior is undefined:

  7. Can a class member function template be virtual?
  8. I have heard that C++ class member function templates can't be virtual. Is this true?

    If they can be virtual, what is an example of a scenario in which one would use such a function?

Saturday, April 10, 2021

error : Please use the /MD switch for _AFXDLL builds

#error Please use the /MD switch for _AFXDLL builds

  1. #error Please use the /MD switch for _AFXDLL builds
  2. This is a paragraph.I encountered an error in Visual Studio, Please use the /MD switch for _AFXDLL builds so if I undefine the _AFXDLL, will my program go wrong?

    A Solution: Settings for CRT linking and MFC linking must be coherent. So, actually, there are two possible answers at this question:

    1. Use /MT (Properties -> C/C++ -> Code Generation) and static MFC (Properties -> General -> Use of MFC)
    2. Use /MD (Properties -> C/C++ -> Code Generation) and shared MFC (Properties -> General -> Use of MFC)

    Yes it will. What you should do is is go to your Visual Studio project properties:

    In Configuration Properties -> C/C++ -> Code Generation make sure you are using the Multi-threaded Dll for your Runtime Library.

    That will solve your problems.

  3. error Please use the /MD switch for _AFXDLL builds
  4. I have following error

    C:\Program Files\Microsoft Visual Studio 8\VC\atlmfc\include\afxver_.h(77): catastrophic error: #error directive: Please use the /MD switch for _AFXDLL builds
    I have set
    Use MFC in a Static Library
    and
    Multi-threaded Debug (/MTd) in runtime library.

    A Solution: I don't think that code block should be used, it will do more harm than good

    I agree, the build system for Visual C++ application is horrendous, the error messages are indecipherable and I have probably spent more time debugging this side of things than anything else, however, this I believe is the problem and the solution.

    In your project properties, Go to

    Configuration Properties => General Have a look at Use of MFC If this is set to Use MFC in a shared DLL Then go to C++ ==> Code Generation And look at Runtime Library This should be set to Multi Threaded Dll

    Basically what happens is, the first option (Use MFC in a shared DLL) sets the preprocessor directive _AFXDLL the second option (Multi Threaded DLL) sets the compiler directive /Md

    Clear as mud eh?

    I've encountered the same error in a number of different Win32 DLL projects, all of which had /MD switch applied.

    IntelliSense: #error directive: Please use the /MD switch for _AFXDLL builds

    I reported the problem in July 2011 and Microsoft confirmed there was a bug, but promised to fix it in the next major release.

    http://connect.microsoft.com/VisualStudio/feedback/details/650507/intellisense-error-directive-please-use-the-md-switch-for-afxdll-builds

    A Solution: Since submitting this bug report, I've come to realise that it's nothing to do with MFC static libraries. There's just something wrongwith Intellisense. Seemingly, there isn't an easy fix. Trying the following sometimes makes this the erroneous 'error' go away:

    1. C++ Code Generation set to /MT, press Apply and then set it back to /MD (see above)
    2. Close and reopen the Solution
    3. Close and restart Visual Studio
    4. Remove the Project from the Solution and add it back as existing project
    At present, having tried all of the above I'm still stuck with this error message ;-)

    Side Note: Thanks for your advice! That helped and additionally I removed solution's suo file before restarting VS2010.

    A Side Note: Also - check that you are consistent with Release and Debug builds. The configuration properties may be different.

    +1 for "Intellisense problem" My (personal) solution: Restart VS 2010 with admin rights...

  5. Error C1189: #error: Please use the /MD switch for _AFXDLL builds(转)
  6. a collection of ideas works.

fatal error LNK1104: cannot open file 'mfc42d.lib'

when I compile DPHULL demo project (C:\Demo_MFC\DPHull_demo), I ran into a lot of errors. mainly caused by template non-conformance issue due to conversion of 2003 template style.

but after resolved these issues, I still ran into the following errors. the final answer is that one OGLToolsd.lib file was compiled in 2003, it used mfc42d.lib. so these errors are coming from this lib file. after I used new lib file to override the old version, the error is resolved.

1>LINK : fatal error LNK1104: cannot open file 'mfc42d.lib'

Error LNK1104 cannot open file 'mfc42d.lib' GLDouglas C:\Demo_MFC\DPHull_demo\GLDouglas\LINK 1

  1. error LNK1104: cannot open file 'mfc42d.lib'
  2. When I converted VC6 code to Visual Studio 2010 I got error message:

    error LNK1104: cannot open file 'mfc42d.lib' C:\Agent\AgentShared\LINK AgentShared
    How to fix this?.

    solutionAccording to your description, I think there may be some other library the project linked to have depent on mfc42.lib. You can try sending information about the process of the linking session to the Output window. You can do it by opening the project's Property Pages->Configuration Properties->Linker->General->Show Progress and selecting "Display all progress messages (/VERBOSE)" option.

    I suppose there is some parts in the project have not got converted to the new compiler. I suggest you open the project in VS2010, and attempt to convert it. Finally, remember to rebuild the project. According to your description, I think there may be some other library the project linked to have depent on mfc42.lib. You can try sending information about the process of the linking session to the Output window. You can do it by opening the project's Property Pages->Configuration Properties->Linker->General->Show Progress and selecting "Display all progress messages (/VERBOSE)" option.

    I suppose there is some parts in the project have not got converted to the new compiler. I suggest you open the project in VS2010, and attempt to convert it. Finally, remember to rebuild the project.

    I suggest you try create a new project from existing code. Open VC2010, click File->New->Project From Existing Code in main menu, and select the fils of the current projects.

    Or you can Create a new project, and copy the useful codes to the new one. Of course, you should make changes if necessary.

  3. Why VC2010 tries to link the MFC42 dll after I upgraded my VC6 project
  4. I upgraded my Win32 project from VC6 to VC2010, and fixed a lot of codes which only work on VC6, compiling is OK, but when the project began linking, it failed with the following message

    LINK : fatal error LNK1104: cannot open file 'mfc42ud.lib'
    I tried to find where the MFC42ud is referred, but I cannot, it drives me mad. Could anyone help me?

    A Solution OK, at last I resolved it. It is because there are some libs I need link, and there is some linkage information in these libs.

    The reason is the Microsoft VC specified preprocessor #pragma comment(lib, "some.lib")

    Actually it is really a bad solution, especially to link system provided libs, like mfc libs. Even you upgraded the project, it still wants to link the old mfc libs.

    The solution is to ignore the old mfc libs.

  5. This is a paragraph.

  6. This is a paragraph.

  7. This is a paragraph.

  8. This is a paragraph.

  9. This is a paragraph.

  10. This is a paragraph.

  11. This is a paragraph.

  12. This is a paragraph.

  13. This is a paragraph.

  14. This is a paragraph.

  15. This is a paragraph.

  16. This is a paragraph.

  17. This is a paragraph.

  18. This is a paragraph.

  19. This is a paragraph.

  20. This is a paragraph.

Friday, April 2, 2021

typename keyword in C++ template

The purpose of this document is to describe the reasoning behind the inclusion of the typename keyword in standard C++, and explain where, when, and how it can and can't be used.

Note: This page is correct (AFAIK) for C++98/03. The rules have been loosened in C++11.

  1. Dependant Name Hell
  2. When to use the typename keyword to identify dependent types, and when not to.

  3. A Description of the C++ typename keyword
  4. The purpose of this document is to describe the reasoning behind the inclusion of the typename keyword in standard C++, and explain where, when, and how it can and can't be used.

    Note: This page is correct (AFAIK) for C++98/03. The rules have been loosened in C++11..

  5. C++ template typename iterator
  6. Consider the following header file:

  7. Down with typename in the Library!
  8. good paper, complete

  9. std::map::const_iterator template compilation error
  10. I have a template class that contains a std::map that stores pointers to T which refuses to compile:

  11. How to write a C++11 template that can take a const iterator
  12. This is a paragraph.

  13. use of const iterator in template function
  14. This is a paragraph.

  15. Dependent names
  16. very informative.

  17. How to correctly implement custom iterators and const_iterators?
  18. This is a paragraph.

    Focus on Template

  19. cv (const and volatile) type qualifiers
  20. Appear in any type specifier, including decl-specifier-seq of declaration grammar, to specify constness or volatility of the object being declared or of the type being named.

    1. const - defines that the type is constant.
    2. volatile - defines that the type is volatile.

  21. Explicit (full) template specialization
  22. Allows customizing the template code for a given set of template arguments.

  23. Determine Information about System, User, Processes, Hardware...
  24. The never ending 'How do I find' article. Will be updated regularly!

Thursday, April 1, 2021

Error C2238 unexpected token(s) preceding ';'

Error C2238 unexpected token(s) preceding ';' douglas c:\demo_mfc\dphull_demo\douglas\containers.h 248

When I compiled this project: C:\Demo_MFC\DPHull_demo, I got this error. it can be circular dependency among classes issue.

  1. C++ header error C2238 unexpected token ';'
  2. There is a C2238 error in the PauseMenu header file on the line: Game* game; It says that ';' is an unexpected token, as well as: C2143 syntax error: missing ';' before '*' on the same line; I have no idea what's wrong in those files, I thought both files are correct.

  3. Resolve build errors due to circular dependency amongst classes
  4. I often find myself in a situation where I am facing multiple compilation/linker errors in a C++ project due to some bad design decisions (made by someone else :) ) which lead to circular dependencies between C++ classes in different header files (can happen also in the same file). But fortunately(?) this doesn't happen often enough for me to remember the solution to this problem for the next time it happens again.

    So for the purposes of easy recall in the future I am going to post a representative problem and a solution along with it. Better solutions are of-course welcome.

  5. /showIncludes (List Include Files)
  6. Causes the compiler to output a list of the include files. Nested include files are also displayed (files that are included from the files that you include)..

    To set this compiler option in the Visual Studio development environment Open the project's Property Pages dialog box. For details, see Set C++ compiler and build properties in Visual Studio.

    1. Click the C/C++ folder.
    2. Click the Advanced property page.
    3. Modify the Show Includes property.

  7. This is a paragraph.

  8. This is a paragraph.

  9. This is a paragraph.

  10. This is a paragraph.

  11. This is a paragraph.

  12. This is a paragraph.

  13. This is a paragraph.

  14. This is a paragraph.

  15. This is a paragraph.

  16. This is a paragraph.

  17. This is a paragraph.

  18. This is a paragraph.

  19. This is a paragraph.

  20. This is a paragraph.

  21. This is a paragraph.