linux-c-programming.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
From: Scott <drmemory@3rivers.net>
To: linux-c-programming@vger.kernel.org
Subject: Re: Into the Void
Date: Thu, 27 Jan 2005 10:01:05 -0700	[thread overview]
Message-ID: <20050127170105.GB945@drmemory.local> (raw)
In-Reply-To: <41F867F2.5000201@hq.ntsp.nec.co.jp>

On Thu, Jan 27, 2005 at 12:02:58PM +0800, Ron Michael Khu wrote:
> 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"??

The latter. Jeff was telling me that I had to cast all of the
arguments to (void *), rather than, as you correctly said, the return
value. It doesn't seem to me (or more importantly, to the compiler)
that casting the ARGUMENTS is necessary?

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

I did get it right later in my post, didn't I?
> >Or, I guess, to follow Ron's suggestion too:
> >
> >  ((char*) memcpy ((void *) *data_buf, (void *) bp, len)) [len] = '\0';

> 
> 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...

I'm starting to grok it. I learned C back in the old days before there
was such a thing, and you could pretty much do anything you wanted
with any pointer. Could sure shoot yourself in the foot if you weren't
paying attention! Actually, I suppose back then memcpy and the like
returned char*. To test my understanding: I have to cast the function
because of the indexing operation. If I just ASSIGN the return value,
then the compiler does implicit type-casting for me. As in:

  char *bp;
  bp = memcpy(foo,bar,len);

Thanks for your help; I actually managed to get the program to compile
with no errors, but now am getting a segmentation fault which I can't
track down, so I'll probably be back to plague you folks some more!

Scott.

  reply	other threads:[~2005-01-27 17:01 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
2005-01-27 17:01     ` Scott [this message]
  -- 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=20050127170105.GB945@drmemory.local \
    --to=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).