Re: [Nbd] [NBD]A problem about nbd-client
- To: harryxiyou <harryxiyou@...17...>
- Cc: nbd-general@lists.sourceforge.net
- Subject: Re: [Nbd] [NBD]A problem about nbd-client
- From: Wouter Verhelst <w@...112...>
- Date: Wed, 15 Feb 2012 09:49:32 +0100
- Message-id: <20120215084932.GW2643@...3...>
- In-reply-to: <CAD+1EGNmLb-=nmnLN31TXWjJ-LSnkUvovTGXZC6n_0Ljxw4zWQ@...18...>
- References: <CAD+1EGNmLb-=nmnLN31TXWjJ-LSnkUvovTGXZC6n_0Ljxw4zWQ@...18...>
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
Reply to: