9fans - fans of the OS Plan 9 from Bell Labs
 help / color / mirror / Atom feed
From: erik quanstrom <quanstro@quanstro.net>
To: 9fans@9fans.net
Subject: Re: [9fans] Strings in acid, what am I missing?
Date: Thu, 13 Feb 2014 20:44:41 -0500	[thread overview]
Message-ID: <d054544bb297f9653e77654172198acc@mikro.quanstro.net> (raw)
In-Reply-To: <a682f6f457c714eaa8187f29c2d86a91@yourdomain.dom>

> > the reason that the () are required
> > is that * binds tighter than \s in acid.  one thing that's confusing about
> > acid is main:ca is an *address* of main:ca, not its value.  so *main:ca
> > is the pointer into the bss, and main:ca is the address of that pointer.
>
> So if I understand you correctly, in acid main:ca is the equivalent to
> char ** in C? And furthermore that the \s expression operates on acid
> addresses rather than normal char * in C? From trying things out in
> acid a little bit, it seems like this is the case, but I'm not
> positive.

almost, the \<char> expressions define the type of the object.  you
have to define the type before indirection is sensible.

so you can say x\X (print a 4-byte integer), but *(x\s).

> > the reason cp gives you garbage is it's not initialized.  in fact when
> > i compile this for am64, you can see everthing quite clearly.  it is
> > optimized away!  (it's a good question why a char* is treated differently
> > than a char[].  perhaps there is some dark corner of the standard that
> > implies things.)
>
> I see what you're saying about cp not being initialized, but I
> compiled with the -N option and I assumed that this would rectify the
> situation of things being optimized away.  Interestingly enough if I
> do **main:cp\c in acid it gives me 'W', but *(main:cp\s) gives me
> garbage, whereas *(main:ca\s) gives me "Hello".
>
> Thanks for the response, any other help would be appreciated!

perhaps that's an arguable flaw in the compiler.  in any event, the
correct way to declare something used is
	USED(x, y, z)
this is not a macro, but implemented by the compiler directly.  SET()
is analogous.

- erik



      reply	other threads:[~2014-02-14  1:44 UTC|newest]

Thread overview: 4+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2014-02-12 16:21 Grant R. Mather
2014-02-12 16:38 ` erik quanstrom
2014-02-14  1:38   ` Grant R. Mather
2014-02-14  1:44     ` erik quanstrom [this message]

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=d054544bb297f9653e77654172198acc@mikro.quanstro.net \
    --to=quanstro@quanstro.net \
    --cc=9fans@9fans.net \
    /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).