🚀 go-pugleaf

RetroBBS NetNews Server

Inspired by RockSolid Light RIP Retro Guy

Article View: comp.std.c
Article #1769

Re: Casting pointers

#1769
From: Michael Illgner
Date: Tue, 02 Oct 1990 12:33
39 lines
1592 bytes
in tim@maths.tcd.ie (Timothy Murphy) writes:

>I recently came across the following problem,
>when temporarily 'borrowing' od from Unix to Mac.
>Consider a program like this.

>#include <stdio.h>

>char *buf = "abc";

>main()
>{
>  int *n = (int*) buf;
>  printf("%d", *n);
>}

>Should this always work?
>On the Mac, with THINK C,
>it only works if buf has an even address.
>Otherwise it bombs out.
>Is that a bug, according to standard C?

>-- 

>Timothy Murphy  

>e-mail: tim@maths.tcd.ie

I think it is a problem with the Macs 680X0 processor. Larger objects like
integer number are aligned at even addresses, and if they are accessed at
an odd address, the processor raises an exception.


|-----------------------------------------------------------------------------|
|It`s not dead,          | Michael Illgner          | email to                |
|It justs smells funny ! | Theodorstr. 27           |                         |
|                        | 4790 Paderborn (Germany) | fillg1@uni-paderborn.de |
|Life, Universe and all  | 05251/26488 or 60-2331   |                         |
------------------------------------------------------------------------------|
Technical Details
Message-ID: <1990Oct2.123350.20527@uni-paderborn.de>
Path: arc1-ca.pugleaf.net!utzoo!attcan!uunet!mcsun!unido!pbinfo!fillg1
References: <1990Sep29.201144.23113@maths.tcd.ie>

Show Full Headers
Complete Article Headers
Path: arc1-ca.pugleaf.net!utzoo!attcan!uunet!mcsun!unido!pbinfo!fillg1
From: fillg1@uni-paderborn.de (Michael Illgner)
Newsgroups: comp.std.c
Subject: Re: Casting pointers
Keywords: Pointers, casting
Message-ID: <1990Oct2.123350.20527@uni-paderborn.de>
Date: 2 Oct 90 12:33:50 GMT
References: <1990Sep29.201144.23113@maths.tcd.ie>
Organization: Uni-GH Paderborn, West Germany
Lines: 39