Domanda

A mysterious function Function '_ZNSsaSERKSs' appears in my gcov report which i have absolutely no idea what it is , can someone can explain to me what is happening

Thanks

Header file

#ifndef CASHIER_H
#define CASHIER_H
#include <string>
using namespace std;


class cashier 
{
public:

        void setID(string);
    string getID();

    void setPassword(string);
    string getPassword();

    void settries(int);
    int gettries();
        void increase_tries();

private:
    string ID;
    string Password;
    int tries;



};

#endif  /* CASHIER_H */

Implementation file

#include "cashier.h"




void cashier::setID(string value)
{
    this->ID = value;
}

void cashier::setPassword(string value)
{

    this->Password = value;

}

string cashier::getID()
{
    return this->ID;
}

string cashier::getPassword()
{
    return this->Password;
}

void cashier::settries(int value)
{
    this->tries=value;
}
int cashier::gettries()
{
    return this->tries;
}
void cashier::increase_tries()
{
    this->tries = this->tries + 1 ;

}

I type in the following command

gcov -f cashier.gnco

I got the following results B

Function '_ZN7cashier8settriesEi' 
Lines executed:100.00% of 3       


Function '_ZN7cashier8gettriesEv'
Lines executed:100.00% of 2

Function '_ZN7cashier14increase_triesEv'
Lines executed:100.00% of 3

Function '_ZN7cashier11getPasswordEv'
Lines executed:100.00% of 2

Function '_ZN7cashier5getIDEv'
Lines executed:100.00% of 2

Function '_ZNSsaSERKSs' //mysterious function
Lines executed:0.00% of 2

Function '_ZN7cashier11setPasswordESs'
Lines executed:100.00% of 3

Function '_ZN7cashier5setIDESs'
Lines executed:100.00% of 3

File 'cashier.cpp'
Lines executed:100.00% of 18
cashier.cpp:creating 'cashier.cpp.gcov'

File '/usr/include/c++/4.4/bits/basic_string.h'
Lines executed:0.00% of 2
/usr/include/c++/4.4/bits/basic_string.h:creating 'basic_string.h.gcov'





 File '/usr/include/c++/4.4/bits/basic_string.h'
    Lines executed:0.00% of 2
    No branches
    Calls executed:0.00% of 1
    /usr/include/c++/4.4/bits/basic_string.h:creating 'basic_string.h.gcov

EDIT

È stato utile?

Soluzione

Using c++filt to demangle the name gives

std::string::operator=(std::string const&)

the copy-assignment operator for std::string.

Altri suggerimenti

As described by others, you need to use c++filt to translate the names from 'mangled' form into human-readable. c++filt takes standard input, detects mangled C++ strings and writes to output with the names corrected; so, e.g. gcov -f filename | c++filt

The source of your problem is taking std::string by value in a header file and putting the function body into an implementation, this prevents the compiler from doing clever optimizations and forces it to construct temporary std::strings.

void setID(string);
void setPassword(string);

These functions are trivial enough that you ought to put their implementations in the header file so that the compiler can inline them if need be. But ultimately, what you need to do is accept references.

void setID(const std::string& id)
{
    this->m_id = id;
}

void setPassword(const std::string& password)
{
    m_password = password;
}

(The 'm_' prefix for member variables is one of the more widely used methods for distinguishing member names from variable names).

This saves the compiler the need to create an intermediate temporary and copy the text from the source string. If your performance is still an issue, you may want to look at C++11s rvalues:

void setPassword(std::string&& password);
Autorizzato sotto: CC-BY-SA insieme a attribuzione
Non affiliato a StackOverflow
scroll top