9fans - fans of the OS Plan 9 from Bell Labs
 help / color / mirror / Atom feed
From: jmk@plan9.bell-labs.com
To: 9fans@cse.psu.edu
Subject: Re: [9fans] Compilation error??
Date: Wed, 30 May 2001 19:09:54 -0400	[thread overview]
Message-ID: <20010530230957.835E319A2D@mail.cse.psu.edu> (raw)

On Wed May 30 18:57:33 EDT 2001, mike@ducky.net wrote:
> >you can't use typestr anymore.  it's a reserved word.
> 
> But what does it do?  I just spent a few minutes looking
> at the compiler source, and it was not obvious to me.

Typestr was one of the things to come out of Ken's parting
flurry of activity. Here's the complete documentation as we have
it from his show-and-tell a couple of days before he left:

#include	<u.h>
#include	<libc.h>

typestr	struct	_cmplx	Cmplx;
struct	_cmplx
{
	double	r;
	double	i;
};
int	Zconv(va_list*, Fconv*);

#pragma	varargck	type	"Z"	Cmplx

void
main(void)
{
	Cmplx a, b;
	int ia[10];
	double d;

	fmtinstall('Z', Zconv);
	a = (Cmplx){1, 0};
	b = (Cmplx){0, 1};

	a = -((a + b) - (b - a)) + -((a - b) - (b + a));
	print("a = %Z\n", a);
	a += b;
	print("a = %Z\n", a);

	if(a == a)
		print("ok\n");

	a = (d = a);
	print("d = %g\n", d);
	print("a = %Z\n", a);

	a = (Cmplx)1.0;
	print("a = %Z\n", a);
}

/*
 * print conversion
 */
int
Zconv(va_list *arg, Fconv *fp)
{
	char s[50];
	Cmplx z;

	z = va_arg(*arg, Cmplx);
	sprint(s, "(%g %g)", z.r, z.i);
	strconv(s, fp);
	return sizeof(z);
}

/*
 * operators
 */
Cmplx
_cmplx_pos_(Cmplx a)
{
	Cmplx r;

	r.r = +a.r;
	r.i = +a.i;
	return r;
}

Cmplx
_cmplx_neg_(Cmplx a)
{
	Cmplx r;

	r.r = -a.r;
	r.i = -a.i;
	return r;
}

Cmplx
_cmplx_add_(Cmplx a, Cmplx b)
{
	Cmplx r;

	r.r = a.r + b.r;
	r.i = a.i + b.i;
	return r;
}

Cmplx
_cmplx_sub_(Cmplx a, Cmplx b)
{
	Cmplx r;

	r.r = a.r - b.r;
	r.i = a.i - b.i;
	return r;
}

int
_cmplx_eq_(Cmplx a, Cmplx b)
{
	Cmplx r;

	return a.r == b.r && a.i == b.i;
}

/*
 * assignment-op (can be made from assig and op)
 */
Cmplx
_cmplx_asadd_(Cmplx *a, Cmplx b)
{
	*a = *a + b;
	return *a;
}

Cmplx
_cmplx_assub_(Cmplx *a, Cmplx b)
{
	*a = *a - b;
	return *a;
}

/*
 * conversions
 */
int
_cmplx_i_(Cmplx a)
{
	return sqrt(a.r*a.r + a.i*a.i);
}

double
_cmplx_d_(Cmplx a)
{
	return sqrt(a.r*a.r + a.i*a.i);
}

Cmplx
_d_cmplx_(double a)
{
	Cmplx r;

	r.r = a;
	r.i = 0;
	return r;
}


             reply	other threads:[~2001-05-30 23:09 UTC|newest]

Thread overview: 9+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2001-05-30 23:09 jmk [this message]
2001-05-31  2:38 ` Ish Rattan
2001-05-31  3:23   ` philw
2001-06-01  8:24     ` bs
2001-06-01  8:46       ` Matt
  -- strict thread matches above, loose matches on Subject: below --
2001-05-31 11:08 rog
2001-05-30 21:31 Russ Cox
2001-05-30 22:46 ` Mike Haertel
2001-05-30 20:15 Ish Rattan

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=20010530230957.835E319A2D@mail.cse.psu.edu \
    --to=jmk@plan9.bell-labs.com \
    --cc=9fans@cse.psu.edu \
    /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).