On Wed, Feb 15, 2012 at 11:41:12AM +0800, harryxiyou wrote:
> nbd-client.c
>
> ....
> int opennet(char *name, int port, int sdp) {
> int sock;
> char portstr[6];
> struct addrinfo hints;
> struct addrinfo *ai = NULL;
> struct addrinfo *rp = NULL;
> int e;
>
> snprintf(portstr, sizeof(portstr), "%d", port);
>
> memset(&hints,'\0',sizeof(hints));
> ....
> }
> .....
>
> I don't know why we use 'memset(&hints,'\0',sizeof(hints));', what
> about 'memset(&hints,0,sizeof(hints));' instead?
There isn't much of a practical difference, really. '\0' is "the
character to end a string with", which is a null (zero) byte. 0 is "the
number zero", which (after a cast) is the same thing as '\0'.
The only difference is that '\0' is a char, whereas 0 is an int. Since
memset wants a char, compilers might warn about passing 0 rather than
'\0'. But in practice...
> I usually use 'memset(&hints,0,sizeof(hints));'
... this will work, too.
> to initialize these memory. Cloud anyone tell me the difference beween
> these two methods? Actually i think '\0' is a terminal character of
> an array, right?
That too, yes.
--
The volume of a pizza of thickness a and radius z can be described by
the following formula:
pi zz a
------------------------------------------------------------------------------
Virtualization & Cloud Management Using Capacity Planning
Cloud computing makes use of virtualization - but cloud computing
also focuses on allowing computing to be delivered as a service.
http://www.accelacomm.com/jaw/sfnl/114/51521223/
_______________________________________________
Nbd-general mailing list
[email protected]
https://lists.sourceforge.net/lists/listinfo/nbd-general