🚀 go-pugleaf

RetroBBS NetNews Server

Inspired by RockSolid Light RIP Retro Guy

Article View: comp.sys.atari.st
Article #1688

Re: C for the ST

#1688
From: Tony Mountifield
Date: Thu, 16 Apr 1992 11:34
42 lines
1960 bytes
In article <12428@tamsun.tamu.edu> jmb8302@csseq.cs.tamu.edu (Jeffrey M Bilger) writes:
> 
>  Has anyone had problems with using the malloc() with Laser C.
> I typed in some simple code to use linked lists and when I try to access 
> any of the nodes my ST bombs with a bus error. Here's the code:
>  
>  struct node 
>   {
>    int color;
>    struct node *next;
>   };
> typedef struct node *next_ptr;
> 
> main()
>  {
>   next_ptr n;
> 
>   n = (next_ptr) malloc(sizeof(node));
>   /* allocates a node, size of the structure, and type casts it to next_ptr*/
>   n->color = 1;
>   n->next  = NULL;       
> 
> /* I build some more nodes, and link em together. But I get a bus error...*/

I'm not familiar with Laser C, but if it has 16-bit ints, then the above
code takes the low 16 bits of the address malloc is trying to return,
sign extends it, and puts it in n, with a value nothing like what was
intended. You should add the line:

	void *malloc();

to specify that malloc() returns a pointer.

There may be a header file <malloc.h> that you can include instead.

-- 
Tony Mountifield     (G4CJO)       | Microware Systems (UK) Ltd.
Email:  tony@microware.co.uk       | Colden Common, WINCHESTER, SO21 1TH.
(or:  ...!uknet!mwuk!tony)         | Tel: 0703 601990   Fax: 0703 601991
------------------------------------------------------------------------
** Any opinions are mine, not Microware's - but you knew that anyway. **
------------------------------------------------------------------------
Technical Details
Message-ID: <921@mwuk.UUCP>
Path: arc1-ca.pugleaf.net!sparky!uunet!mcsun!uknet!pyrltd!mwuk!tony
References: <1992Apr11.201039.18@wsuhub.uc.twsu.edu> <pal.703177751@regent.e-technik.tu-muenchen.de> <12428@tamsun.tamu.edu>

Show Full Headers
Complete Article Headers
Path: arc1-ca.pugleaf.net!sparky!uunet!mcsun!uknet!pyrltd!mwuk!tony
From: tony@microware.co.uk (Tony Mountifield)
Newsgroups: comp.sys.atari.st
Subject: Re: C for the ST
Message-ID: <921@mwuk.UUCP>
Date: 16 Apr 92 11:34:08 GMT
References: <1992Apr11.201039.18@wsuhub.uc.twsu.edu> <pal.703177751@regent.e-technik.tu-muenchen.de> <12428@tamsun.tamu.edu>
Organization: Microware Systems (UK) Ltd., Winchester, UK.
Lines: 42