Subject: | |
From: | |
Reply To: | |
Date: | Wed, 27 Apr 2005 17:11:51 +0100 |
Content-Type: | text/plain |
Parts/Attachments: |
|
|
On 4/27/05, Ken Hirsch <[log in to unmask]> wrote:
>This is not true of C in general, just C on most machines. The C
>standard requires those casts for a reason. From an old USENET C FAQ:
OK - I stand corrected. I've never used any of those other machines.
<snip>
>The old HP 3000 series uses a different addressing scheme for byte
>addresses than for word addresses; like several of the machines above it
>therefore uses different representations for char * and void * pointers
>than for other pointers.
That may be the case but it doesn't manifest itself (easily) when you use
the C compiler on that system. I'd be interested to see a program that
demonstrates it. This is my attempt -
#include <stdio.h>
#include <memory.h>
main(int argc, char *argv[])
{
int *mybuff = (int *)malloc(100);
/* Assign from int * to char * without and with casting */
char *c_mybuff1 = mybuff;
char *c_mybuff2 = (char *)mybuff;
/* Put something in mybuff */
strcpy((char *)mybuff, "Hello!");
/* The following displays Hello! twice. */
printf("c_mybuff1 = %s\n", c_mybuff1);
printf("c_mybuff2 = %s\n", c_mybuff2);
}
$ make Z9
c89 -O -o Z9 Z9.c
cc: "/DEV/DEV/PETERS/Z9.c", line 8: warning 604: Pointers are not
assignment-com
patible.
$ ./Z9
c_mybuff1 = Hello!
c_mybuff2 = Hello!
$ uname -a
MPE/iX QAHP3K C.70.00 C.39.06 SERIES 979-200
$
Maybe I need to use an older version of MPE or another compiler? I tried
using "short" instead of "int" so that it was a nice 16 bit word. Trouble
is, I'm compiling 32 bit so this must complicate matters. Maybe I need to
compile in 16 bit mode? I'm not sure how to do that.
Cheers.
Peter
--
http://www.beluga.freeserve.co.uk
* To join/leave the list, search archives, change list settings, *
* etc., please visit http://raven.utc.edu/archives/hp3000-l.html *
|
|
|