Menu

cppcheck suggests to use references on a C API code block

2017-08-15
2017-08-15
  • Wilson E. Alvarez

    On a pull request I worked on, cppcheck (version 1.80) showed a suggestion to use references on a C API when references do not exist in C.

    The source code scanned can be found here, and the messages I got were the following:

    [modules/nativescript/godot_nativescript.cpp:52]: (performance) Function parameter 'p_create_func' should be passed by reference.
    [modules/nativescript/godot_nativescript.cpp:52]: (performance) Function parameter 'p_destroy_func' should be passed by reference.
    [modules/nativescript/godot_nativescript.cpp:77]: (performance) Function parameter 'p_create_func' should be passed by reference.
    [modules/nativescript/godot_nativescript.cpp:77]: (performance) Function parameter 'p_destroy_func' should be passed by reference.
    [modules/nativescript/godot_nativescript.cpp:101]: (performance) Function parameter 'p_method' should be passed by reference.
    [modules/nativescript/godot_nativescript.cpp:120]: (performance) Function parameter 'p_set_func' should be passed by reference.
    [modules/nativescript/godot_nativescript.cpp:120]: (performance) Function parameter 'p_get_func' should be passed by reference.
    

    I did some performance tests to check if there was a performance gain anyway, but so far I do not see it. I think this might be a bug.

     
  • Daniel Marjamäki

    if it is C code then the cpp extension is confusing. the --language option can be used if you don't want c++ warnings.

    I did some performance tests to check if there was a performance gain anyway, but so far I do not see it. I think this might be a bug.

    there can be performance gains.

    The "performance" messages is for generic suboptimisations. I think that profiling and fixing actual performance issues will give you more noticeable improvements.

     
  • Wilson E. Alvarez

    Thanks a lot for the clarification! And thanks a lot for this awesome static analyzer!

    I got to say, most of the time the most important cppcheck messages I've seen are spot-on and they work with barely any configuration at all. I've used cppcheck every now and then for about a year now and it's amazing.

     

Log in to post a comment.

Want the latest updates on software, tech news, and AI?
Get latest updates about software, tech news, and AI from SourceForge directly in your inbox once a month.