473,396 Members | 1,913 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,396 software developers and data experts.

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::XPCException(char*).
"XPCFileStat.C", line 20: Warning: String literal converted to char* in formal argument sMsg in call to XPCException::XPCException(char*).
"XPCFileStat.C", line 28: Warning: String literal converted to char* in formal argument sMsg in call to XPCException::XPCException(char*).
"XPCFileStat.C", line 36: Warning: String literal converted to char* in formal argument sMsg in call to XPCException::XPCException(char*).
"XPCFileStat.C", line 48: Warning: String literal converted to char* in formal argument sMsg in call to XPCException::XPCException(char*).
"XPCFileStat.C", line 59: Warning: String literal converted to char* in formal argument sMsg in call to XPCException::XPCException(char*).
"XPCFileStat.C", line 70: Warning: String literal converted to char* in formal argument sMsg in call to XPCException::XPCException(char*).
"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::XPCException(char*).
"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::XPCFileStat()
{
long lMaxpath;

// Determine the maximum size of a pathname
if ((lMaxpath = pathconf("/", _PC_PATH_MAX)) == -1)
{
XPCException newExcept("Could 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("Could not allocate memory for cFileName"); // warning line 20
throw newExcept;
return;
}

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

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

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

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

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

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

strcpy(cFileName, _oldClass.sGetFileName());

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

enum eDirectoryTypes XPCFileStat::iGetFileType()
{
// 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::iGetOwnerPermissions()
{
// Extract the owner permission bits and return the appropriate
// permission value

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

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

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

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

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

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

if (sizeof(cFileName) < sizeof(_oldClass.sGetFileName()))
{
delete [] cFileName;
cFileName = new char[sizeof(cFileName)];
if (!cFileName)
{
XPCException newExcept("Could not allocate memory for cFileName"); // warning line 221
throw newExcept;
return *this;
}
}

memcpy((void *)cFileName, (void *)_oldClass.sGetFileName(), sizeof(_oldClass.sGetFileName()));
memcpy((void *)&sStatBuf, (void *)&_oldClass.getStatBuf(), 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


Jul 19 '05 #1
1 2686

"Azzedine" <a.********@bwk.tue.nl> wrote in message news:bo**********@news.tue.nl...
"XPCFileStat.C", line 11: Warning: String literal converted to char* in formal argument sMsg in call to XPCException::XPCException(char*).

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*.
"XPCFileStat.C", line 77: Error: The "&" operator can only be applied to a variable or other l-value.

memcpy((void *)&sStatBuf, (void *)&_oldClass.getStatBuf(), sizeof(struct stat)); //here is first error
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.getStatBuf();
memcpy((void *)cFileName, (void *)_oldClass.sGetFileName(), sizeof(_oldClass.sGetFileName()));
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?
memcpy((void *)&sStatBuf, (void *)&_oldClass.getStatBuf(), sizeof(struct stat)); // here is the 2 error


Same problem as before.
Jul 19 '05 #2

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

0
by: Martin Bless | last post by:
I need to access a MSSQL database (MS-Sql, not MySQL!)and would very much like to use mssql-0.09.tar.gz which is available from http://www.object-craft.com.au/projects/mssql/download.html ...
0
by: pruebauno | last post by:
Hello all, I am having issues compiling Python with large file support. I tried forcing the configure script to add it but then it bombs in the make process. Any help will be appreciated. ...
11
by: Arturo DiDonna | last post by:
Hello everyone. I am trying to compile someone else code and I am stuck with compilation problems using the g++ 3.3 compiler. Basically, when compiling the following code, I get this error...
4
by: Aaron Queenan | last post by:
When I build a C++ library to .NET using the managed C++ compiler, I get the following error message: Linking... LINK : error LNK2020: unresolved token (0A000005) _CrtDbgReport LINK : error...
1
by: Jim Heavey | last post by:
Hello, trying to round out my knowlege here about compiling. To date I have used VS.Net to do all my compiling "majically", but I want to understand how to do it on my own, should the need ever...
1
by: Mike Hutton | last post by:
I need some help. I am trying to set up our development environment so as to make life easy for my fellow developers (none of whom have used ASP.NET or VS.NET before). We are developing our...
6
by: Josefo | last post by:
Hello all. I am a newbie following the C++ tutorial in : http://www.cplusplus.com/doc/tutorial/templates.html I am unable to succesfully compile any of the examples with templates of this...
8
by: WebSnozz | last post by:
I have an application written in C that does a lot of low level stuff. It does a lot of things like casting from void*'s. I want to create a new GUI for it in either C# or MC++, but reuse the...
6
by: Cybex | last post by:
I am taking a C++ class and would like to use a Linux based IDE vs C+ + .Net but I am a little lost in how to go about this. I think that the IDE and compilation tools are separate under Linux. I...
2
by: renagade629 | last post by:
Can anybody help me understand what i'm doing wrong or what I'm missing? Is there anyother good and commendable C++ program I can use (free) from the internet like Dev C++? I'm having trouble doing...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
0
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
0
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
0
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...
0
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows...
0
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each...
0
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing,...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.