linux-c-programming.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
From: Ron Michael Khu <ronkhu@ntsp.nec.co.jp>
To: Scott <drmemory@3rivers.net>, linux-c-programming@vger.kernel.org
Subject: Re: Into the Void
Date: Thu, 27 Jan 2005 12:02:58 +0800	[thread overview]
Message-ID: <41F867F2.5000201@hq.ntsp.nec.co.jp> (raw)
In-Reply-To: <20050126161137.GA954@drmemory.local>

extra typing?? r u using the term "type" in the same context as "data 
type"(progamming language concept)?
or "type" in the sense "keyboard typing"??

>>So I should use
>> memcpy ((void *) *data_buf, (void *) bp, len) [len] = '\0';

Oops, I think u've misunderstood jeff's reply...
What jeff and the others are trying to say is that the return value of 
memcpy() is of type "void *"

In essence:
void *ptr;
ptr = memcpy(...)

thus, u need to cast the return value to something more appropriate.

And by the way, 
"memcpy ((void *) *data_buf, (void *) bp, len) [len] = '\0';" is WRONG

u still need to cast it properly if ur u persist on doing it the "one-liner way":
( (char*)memcpy ((void *) *data_buf, (void *) bp, len) )[len] = '\0';

*TAKE NOTE of the enclosing parenthesis:
((char*)SOMETHING)[index] ='\0'   

(assuming of course SOMETHING is something that could safely be treated as char *)

and like what George stated earlier... this one-liner thing is a maintenance 
headache(a code readability issue), and thus, not advisable.
better chop that one-liner down to something more readable/maintanable.

-Ron

P.S. Hmmmm... u seem to have trouble understanding what a "void*" is.
Void * could be anything.. thus u cant simply go around indexing a void*
and treating it like an array without properly casting it...



Scott wrote:

>On Wed, Jan 26, 2005 at 08:45:09AM -0500, Jeff.Fellin@rflelect.com wrote:
>  
>
>>The reason you are getting the references to void is the function prototype
>>for memcpy is:
>>
>>      memcpy (void *dest, void *src, size_t n);
>>
>>You are passing char* pointers which are not void * pointers. You have to
>>correct your arguments
>>to remove the error messages. Please use man memcpy() for more details.
>>    
>>
>
>So I should use
>
>   memcpy ((void *) *data_buf, (void *) bp, len) [len] = '\0';
>
>(len is already type size_t) 
>
>Or, I guess, to follow Ron's suggestion too:
>
>   ((char*) memcpy ((void *) *data_buf, (void *) bp, len)) [len] = '\0';
>
>Just curious as to what evil all of this extra typing is supposed to
>be protecting me from?
>-
>To unsubscribe from this list: send the line "unsubscribe linux-c-programming" in
>the body of a message to majordomo@vger.kernel.org
>More majordomo info at  http://vger.kernel.org/majordomo-info.html
>
>
>  
>



  reply	other threads:[~2005-01-27  4:02 UTC|newest]

Thread overview: 12+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2005-01-26 13:45 Into the Void Jeff.Fellin
2005-01-26 16:11 ` Scott
2005-01-27  4:02   ` Ron Michael Khu [this message]
2005-01-27 17:01     ` Scott
  -- strict thread matches above, loose matches on Subject: below --
2005-02-02 18:17 Huber, George K RDECOM CERDEC STCD SRI
2005-02-01 15:32 Huber, George K RDECOM CERDEC STCD SRI
2005-02-02 12:15 ` Glynn Clements
2005-01-27 17:58 Huber, George K RDECOM CERDEC STCD SRI
2005-01-28  4:36 ` Amit Dang
2005-01-26 16:02 Huber, George K RDECOM CERDEC STCD SRI
2005-01-26  0:09 Scott
2005-01-26  2:18 ` Ron Michael Khu

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=41F867F2.5000201@hq.ntsp.nec.co.jp \
    --to=ronkhu@ntsp.nec.co.jp \
    --cc=drmemory@3rivers.net \
    --cc=linux-c-programming@vger.kernel.org \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).