9fans - fans of the OS Plan 9 from Bell Labs
 help / color / mirror / Atom feed
* [9fans] KenC operator overloading.
@ 2005-05-07 16:56 "Nils O. Selåsdal"
  2005-05-07 16:59 ` Rob Pike
  2005-05-07 18:26 ` jmk
  0 siblings, 2 replies; 3+ messages in thread
From: "Nils O. Selåsdal" @ 2005-05-07 16:56 UTC (permalink / raw)
  To: 9fans

Hello,

I recently ventured down the cmd/cc/ sources. And what did I discover ?
Take a peek of the following (sorry ass of an -) example and see yourself.

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

struct Foo {
	int x,y;
};

typestr struct Foo Foo;

Foo Foo_add_(Foo a,Foo b)
{
	return (Foo){a.x+b.x, a.y+b.y};
}

void main(void)
{
	Foo f1 = {1,1},f2 = {2,2},f3;
	f3 = f1 + f2;

	print("%d,%d\n",f3.x,f3.y);	
	exits(nil);
}

Neat, no ?

Any particular reason this isn't documented ?

--
Nils O. Selåsdal


^ permalink raw reply	[flat|nested] 3+ messages in thread

end of thread, other threads:[~2005-05-07 18:26 UTC | newest]

Thread overview: 3+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2005-05-07 16:56 [9fans] KenC operator overloading "Nils O. Selåsdal"
2005-05-07 16:59 ` Rob Pike
2005-05-07 18:26 ` jmk

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