9fans - fans of the OS Plan 9 from Bell Labs
 help / color / mirror / Atom feed
* Re: [9fans] thread
@ 2001-07-06  1:02 rob pike
  0 siblings, 0 replies; 12+ messages in thread
From: rob pike @ 2001-07-06  1:02 UTC (permalink / raw)
  To: 9fans

[-- Attachment #1: Type: text/plain, Size: 32 bytes --]

Unnecessary, anyway.

-rob


[-- Attachment #2: Type: message/rfc822, Size: 1370 bytes --]

From: arisawa@ar.aichi-u.ac.jp
To: 9fans@cse.psu.edu
Subject: [9fans] thread
Date: Fri, 6 Jul 2001 09:50:20 +0900
Message-ID: <20010706010009.D94AF199C0@mail.cse.psu.edu>

Hello 9fans,

Manual of thread shows the example codes such as:
	char m[48];
	...
	{nil,   &m,     CHANRCV},
I wonder that &m is a typo.

Thanks,

Kenji Arisawa
E-mail: arisawa@aichi-u.ac.jp

^ permalink raw reply	[flat|nested] 12+ messages in thread
* Re: [9fans] thread
@ 2001-07-06  5:55 dmr
  2001-07-06 16:54 ` Digby Tarvin
  0 siblings, 1 reply; 12+ messages in thread
From: dmr @ 2001-07-06  5:55 UTC (permalink / raw)
  To: 9fans

So far as I can determine, the Plan 9 C compiler is
conformant here.

If you have, say, an

	int A[10];

then just A is the address of A and has type int *.
&A is a pointer to this array of 10 integers; it will
have the same value, as a pointer, but a different type:

 int (*)[10]

The reason why the initialization in the thread man page,
(and presumably the code) works is that the thing being
assigned to is void *, and any object pointer will fit; the
coercion just happens.

The & in &m is redundant, probably misleading, but ultimately
harmless.  Kenji's example with print likewise has the
same character, since print is a variadic function, and all
his second arguments fall under the ... in its declaration,
and so aren't type-checked.

Incidentally, there is no C-language guarantee that the
actual bit pattern produced by A and &A will be identical,
though in practice they usually will be for most compilers,
yet they still have different types.

For a case in which the type-checking is more evident, without
the laxness of void * or ..., try compiling

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

void t1(int *ip);
void t2(int (*iap)[10]);

void
main(void)
{
	int ia[10];

	t1(ia);
	t1(&ia);
	t2(ia);
	t2(&ia);
}

You will get errors on lines 13 [ t1(&ia) ] and
14 [ t2(ia) ].

	Dennis


^ permalink raw reply	[flat|nested] 12+ messages in thread
* Re: [9fans] thread
@ 2001-07-06  4:15 arisawa
  2001-07-06 14:41 ` Dan Cross
  0 siblings, 1 reply; 12+ messages in thread
From: arisawa @ 2001-07-06  4:15 UTC (permalink / raw)
  To: 9fans

Thank you, Dan,

You say:
>No, &m in this context is perfectly legal C.  ``&'' in C says
>to take the address of the referenced object (m)

But, how can I understand the following result?

#include <libc.h>
main(){
	int a[1];
	a[0] = 10;
	print("%d\n",*a);
	print("%d\n",a);
	print("%d\n",&a);
	print("%d\n",*&a);
	print("%d\n",*(&a));
	print("%d\n",*(a));
}

The output is:
10
2147479448
2147479448
2147479448
2147479448
10

Kenji Arisawa
E-mail: arisawa@aichi-u.ac.jp


^ permalink raw reply	[flat|nested] 12+ messages in thread
* [9fans] thread
@ 2001-07-06  0:50 arisawa
  2001-07-06  2:05 ` Dan Cross
  0 siblings, 1 reply; 12+ messages in thread
From: arisawa @ 2001-07-06  0:50 UTC (permalink / raw)
  To: 9fans

Hello 9fans,

Manual of thread shows the example codes such as:
	char m[48];
	...
	{nil,   &m,     CHANRCV},
I wonder that &m is a typo.

Thanks,

Kenji Arisawa
E-mail: arisawa@aichi-u.ac.jp


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

end of thread, other threads:[~2001-07-09 17:03 UTC | newest]

Thread overview: 12+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2001-07-06  1:02 [9fans] thread rob pike
  -- strict thread matches above, loose matches on Subject: below --
2001-07-06  5:55 dmr
2001-07-06 16:54 ` Digby Tarvin
2001-07-09  8:33   ` Douglas A. Gwyn
2001-07-09 11:46     ` Digby Tarvin
2001-07-09 17:03       ` Dan Cross
2001-07-09 11:49     ` Boyd Roberts
2001-07-06  4:15 arisawa
2001-07-06 14:41 ` Dan Cross
2001-07-06 18:24   ` Boyd Roberts
2001-07-06  0:50 arisawa
2001-07-06  2:05 ` Dan Cross

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