Compiling error

Collapse
This topic is closed.
X
X
 
  • Time
  • Show
Clear All
new posts
  • Azzedine

    Compiling error

    Dear All,

    I compiled a project under Unix, I have got the following errors:

    ------------------------------------------
    CC -I. -DUNIX -c XPCFileStat.C -g -o XPCFileStat.o
    "XPCFileStat.C" , line 11: Warning: String literal converted to char* in formal argument sMsg in call to XPCException::X PCException(cha r*).
    "XPCFileStat.C" , line 20: Warning: String literal converted to char* in formal argument sMsg in call to XPCException::X PCException(cha r*).
    "XPCFileStat.C" , line 28: Warning: String literal converted to char* in formal argument sMsg in call to XPCException::X PCException(cha r*).
    "XPCFileStat.C" , line 36: Warning: String literal converted to char* in formal argument sMsg in call to XPCException::X PCException(cha r*).
    "XPCFileStat.C" , line 48: Warning: String literal converted to char* in formal argument sMsg in call to XPCException::X PCException(cha r*).
    "XPCFileStat.C" , line 59: Warning: String literal converted to char* in formal argument sMsg in call to XPCException::X PCException(cha r*).
    "XPCFileStat.C" , line 70: Warning: String literal converted to char* in formal argument sMsg in call to XPCException::X PCException(cha r*).
    "XPCFileStat.C" , line 77: Error: The "&" operator can only be applied to a variable or other l-value.
    "XPCFileStat.C" , line 221: Warning: String literal converted to char* in formal argument sMsg in call to XPCException::X PCException(cha r*).
    "XPCFileStat.C" , line 228: Error: The "&" operator can only be applied to a variable or other l-value.
    2 Error(s) and 8 Warning(s) detected.
    *** Error code 2
    make: Fatal error: Command failed for target `XPCFileStat.o'
    ------------------------------------------------------
    Here is the main part of the program:

    #include <XPCFileStat. h>
    #include <iostream.h>

    XPCFileStat::XP CFileStat()
    {
    long lMaxpath;

    // Determine the maximum size of a pathname
    if ((lMaxpath = pathconf("/", _PC_PATH_MAX)) == -1)
    {
    XPCException newExcept("Coul d not determine maximum pathname length"); // warning line 11
    throw newExcept;
    return;
    }

    // Allocate memory for the pathname
    cFileName = new char[lMaxpath + 1];
    if (!cFileName)
    {
    XPCException newExcept("Coul d not allocate memory for cFileName"); // warning line 20
    throw newExcept;
    return;
    }

    // Store the current working directory
    if (getcwd(cFileNa me, lMaxpath) == NULL)
    {
    XPCException newExcept("Coul d not get current working directory"); // warning line 28
    throw newExcept;
    return;
    }

    // Retrieve the file's statistics
    if (lstat(cFileNam e, &sStatBuf) == -1)
    {
    XPCException newExcept("Coul d not obtain statics on directory."); // warning line 36
    throw newExcept;
    return;
    }
    }

    XPCFileStat::XP CFileStat(char *_psFileName)
    {
    // Allocate memory to store the pathname
    cFileName = new char[strlen(_psFileN ame)+1];
    if (!cFileName)
    {
    XPCException newExcept("Coul d not allocate memory for cFileName"); // warming line 48
    throw newExcept;
    return;
    }

    // Copy the pathname to the private data member
    strcpy(cFileNam e, _psFileName);

    // Retrieve the file's statistics
    if (lstat(cFileNam e, &sStatBuf) == -1)
    {
    XPCException newExcept("Coul d not obtain statics on directory."); // warning line 59
    throw newExcept;
    return;
    }
    }

    XPCFileStat::XP CFileStat(const XPCFileStat &_oldClass)
    {
    cFileName = new char[sizeof(_oldClas s.cFileName)+1];
    if (!cFileName)
    {
    XPCException newExcept("Coul d not allocate memory for cFileName");// warning line 70
    throw newExcept;
    return;
    }

    strcpy(cFileNam e, _oldClass.sGetF ileName());

    memcpy((void *)&sStatBuf, (void *)&_oldClass.ge tStatBuf(), sizeof(struct stat)); //here is first error
    }

    enum eDirectoryTypes XPCFileStat::iG etFileType()
    {
    // Extract the file type bits from st_mode and match them up with
    // the file type constants

    switch(sStatBuf .st_mode & S_IFMT)
    {
    ............... ...............
    }
    }

    enum ePermissions XPCFileStat::iG etOwnerPermissi ons()
    {
    // Extract the owner permission bits and return the appropriate
    // permission value

    switch(sStatBuf .st_mode & S_IRWXU)
    {
    ............... ............... ............... ..........
    }
    }

    enum ePermissions XPCFileStat::iG etGroupPermissi ons()
    {
    // Extract the group permission bits and return the appropriate
    // permission value

    switch(sStatBuf .st_mode & S_IRWXG)
    {
    ............... ............... ............... .....
    }
    }

    enum ePermissions XPCFileStat::iG etOtherPermissi ons()
    {
    // Extract the "other users" permission bits and return the appropriate
    // permission value

    switch(sStatBuf .st_mode & S_IRWXO)
    {
    ............... ............... ........
    }
    }

    XPCFileStat &XPCFileStat::o perator=(const XPCFileStat &_oldClass)
    {
    if (this == &_oldClass)
    return *this;

    if (sizeof(cFileNa me) < sizeof(_oldClas s.sGetFileName( )))
    {
    delete [] cFileName;
    cFileName = new char[sizeof(cFileNam e)];
    if (!cFileName)
    {
    XPCException newExcept("Coul d not allocate memory for cFileName"); // warning line 221
    throw newExcept;
    return *this;
    }
    }

    memcpy((void *)cFileName, (void *)_oldClass.sGe tFileName(), sizeof(_oldClas s.sGetFileName( )));
    memcpy((void *)&sStatBuf, (void *)&_oldClass.ge tStatBuf(), sizeof(struct stat)); // here is the 2 error
    }

    =============== =============== =============== =============== ===========

    I would be glag if someone would help me to solve at least those two errors. Your help will be appreciated!

    Thank you in advance for your reply.
    Regards,
    Azzedine




  • Ron Natalie

    #2
    Re: Compiling error


    "Azzedine" <a.yahiaoui@bwk .tue.nl> wrote in message news:bore3b$b55 $1@news.tue.nl. ..
    [color=blue]
    > "XPCFileStat.C" , line 11: Warning: String literal converted to char* in formal argument sMsg in call to[/color]
    XPCException::X PCException(cha r*).

    The type of a string literal is really const char[]. However a deprecated conversion is permitted to non-const char. You should
    probably
    clean up your interfaces to use const char*.
    [color=blue]
    > "XPCFileStat.C" , line 77: Error: The "&" operator can only be applied to a variable or other l-value.
    >
    > memcpy((void *)&sStatBuf, (void *)&_oldClass.ge tStatBuf(), sizeof(struct stat)); //here is first error[/color]

    I suspect that getStatBuf() returns a stat*. You don't want the &.
    The void* casts are spurious. Get out of the habit of providing them.

    There's also no reason to use memcpy here. Just more oppurtunity to make errors.
    How about:
    sStatBuf = *_oldClass.getS tatBuf();
    [color=blue]
    > memcpy((void *)cFileName, (void *)_oldClass.sGe tFileName(), sizeof(_oldClas s.sGetFileName( )));[/color]

    The sizeof() here looks dubious. If sGetFileName returns a char*, then sizeof will only be the size of
    the pointer. You probably want strlen here. Again, you do a lot of suffering to maintain these strings
    yourself as character arrays. Why not use the std::string class?
    [color=blue]
    > memcpy((void *)&sStatBuf, (void *)&_oldClass.ge tStatBuf(), sizeof(struct stat)); // here is the 2 error[/color]

    Same problem as before.


    Comment

    Working...