[net.lang.c] Casting aspersions...

ptw@vaxine.UUCP (P. Tucker Withington) (07/11/83)

Speaking of type casts, can anyone explain the following?

	char c;
	int *pi;

	main()
	{

		c = *((char *) pi);
		c = (char) *pi;

On 4.1 generates:

	movb	*_pi,_c
	cvtbl   *_pi,r0                 ; Huh?
	cvtlb	r0,_c

With MIT cc generates:

	movl	pi,a0
	movb	a0@,c
	movl	pi,a0
	movl    a0@,d0                  | Looks better
	movb	d0,c

Is that the reason for:

	/* THIS CODE IS VAX DEPENDENT IN HANDLING %l? AND %c */

	case 'c':
		b = *adx;
		for (i = 24; i >= 0; i -= 8)
			if (c = (b >> i) & 0x7f)
				putchar(c, touser);
		break;

?

				       --Tucker (ptw@vaxine.UUCP)

ka@spanky.UUCP (07/13/83)

	Re:
		int *pi;
		char c;
		c = *pi;
	compiling to:
		cvtbl   *_pi,r0                 ; Huh?
		cvtlb	r0,_c

The code generated by the C compiler is correct.  It is also inefficient;
"movb	*_p1,_c" would be better.  Probably that perticular statement
does not occur too often, so the deficiency in the C compiler is not too
serious.

The code reproduced from printf was designed to handle multiple chacter
constants.  E. g.
	printf("%c\n", 'ab');
should produce:
	ab

Kenneth Almquist