Solved

char* array

Posted on 2006-06-25
6
360 Views
Last Modified: 2010-04-24
I have this code

char             DataPacket[128];
SocketObject ClientSocketObject;

iBytesReceived = ClientSocketObject.Recv(&DataPacket, 128, 0);

and, Recv is defined as,

int SocketObject::Recv( char *szBuffer, int iBufLen, int iFlags)
{
...
}


I'm using Visual Studio.Net 2005,

and when i compile,
i get this error

error C2664: 'SocketObject::Recv' : cannot convert parameter 1 from 'char (*__w64 )[128]' to 'char *'
1>        Types pointed to are unrelated; conversion requires reinterpret_cast, C-style cast or function-style cast


However, this error goes away if i do,

iBytesReceived = ClientSocketObject.Recv(&DataPacket[0], 128, 0);  isntead of
iBytesReceived = ClientSocketObject.Recv(&DataPacket, 128, 0);

and I was wondering if this is the correct way to solve the error. Any explnation will be appreciated. I belive this error does not occur in the old Visual C++ compilers.

Thank you very much
0
Comment
Question by:wonjun
6 Comments
 
LVL 25

Accepted Solution

by:
clockwatcher earned 125 total points
ID: 16980648
iBytesReceived = ClientSocketObject.Recv(DataPacket, 128, 0);

DataPacket should be a pointer to your array of chars.
0
 
LVL 49

Expert Comment

by:DanRollins
ID: 16987887
clockwatcher is correct...

If you have an array...
     char   DataPacket[128];
then...
    DataPacket[0] is a single char (the first one in the array)
    &DataPacket[0] is a pointer to a char (char*)
         (the same as.... )
    DataPacket is a pointer to char (char*)
         (however...)
    &DataPacket is a pointer to that pointer (it's a char**)

The prototype requires a pointer-to-char, so either of these will work:
    &DataPacket[0]
    DataPacket

0
 

Expert Comment

by:patti_nyl
ID: 16992050
Hi!

Remove the & sign!

will result to this
iBytesReceived = ClientSocketObject.Recv(DataPacket, 128, 0);


Patrik
0

Featured Post

How to improve team productivity

Quip adds documents, spreadsheets, and tasklists to your Slack experience
- Elevate ideas to Quip docs
- Share Quip docs in Slack
- Get notified of changes to your docs
- Available on iOS/Android/Desktop/Web
- Online/Offline

Join & Write a Comment

The following diagram presents a diamond class hierarchy: As depicted, diamond inheritance denotes when two classes (e.g., CDerived1 and CDerived2), separately extending a common base class (e.g., CBase), are sub classed simultaneously by a fourt…
In Easy String Encryption Using CryptoAPI in C++ (http://www.experts-exchange.com/viewArticle.jsp?aid=1193) I described how to encrypt text and recommended that the encrypted text be stored as a series of hexadecimal digits -- because cyphertext may…
In this seventh video of the Xpdf series, we discuss and demonstrate the PDFfonts utility, which lists all the fonts used in a PDF file. It does this via a command line interface, making it suitable for use in programs, scripts, batch files — any pl…
Here's a very brief overview of the methods PRTG Network Monitor (https://www.paessler.com/prtg) offers for monitoring bandwidth, to help you decide which methods you´d like to investigate in more detail.  The methods are covered in more detail in o…

747 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question

Need Help in Real-Time?

Connect with top rated Experts

11 Experts available now in Live!

Get 1:1 Help Now