?
Solved

char* array

Posted on 2006-06-25
6
Medium Priority
?
371 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
3 Comments
 
LVL 25

Accepted Solution

by:
clockwatcher earned 500 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

Free Tool: SSL Checker

Scans your site and returns information about your SSL implementation and certificate. Helpful for debugging and validating your SSL configuration.

One of a set of tools we are providing to everyone as a way of saying thank you for being a part of the community.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

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…
Integration Management Part 2
When cloud platforms entered the scene, users and companies jumped on board to take advantage of the many benefits, like the ability to work and connect with company information from various locations. What many didn't foresee was the increased risk…
Suggested Courses

839 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