🚀 go-pugleaf

RetroBBS NetNews Server

Inspired by RockSolid Light RIP Retro Guy

Article View: alt.comp.lang.learn.c-c++
Article #203

Re: C Programming : Need help please .

#203
From: Martin Ambuhl
Date: Mon, 18 Jan 1999 00:00
32 lines
1931 bytes
CalvinKong wrote:
> 
> I had find out the part that causing the problem . But I still don't know
> why it occurs .. Logically , it should be okay . Here is a program that I
> extracted out and modified , please discuss with me ...
> ************************************************************
> # include <stdlib.h>
> typedef struct ListType {
>  int       item;
>  struct ListType *link;
> }Node;
> typedef Node *List;
> 
> int main()
> {
>  List temp;
> 
>  temp = (List)malloc (sizeof(List));

sizeof(List) is just the size of a pointer.
If you would do with a typedef less, you would not confuse yourself:
   Node *temp;
   temp = malloc(sizeof *temp);
/* or, to be slightly less safe, 'temp = malloc(sizeof(Node));' */
remember to check the return value from malloc.




-- 
Martin Ambuhl (mambuhl@earthlink.net)
Note: mambuhl@tiac.net will soon be inactive
Technical Details
Message-ID: <36A2D431.D11CAB41@earthlink.net>
Path: arc1-ca.pugleaf.net!unknown!not-for-mail
References: <36a2cb23.0@news2.tm.net.my>

Show Full Headers
Complete Article Headers
X-Google-Language: ENGLISH,ASCII-7-bit
X-Google-Thread: 109edf,44c9aa94f48f7403
X-Google-Attributes: gid109edf,public
X-Google-Thread: 114592,44c9aa94f48f7403
X-Google-Attributes: gid114592,public
X-Google-Thread: 1011f8,44c9aa94f48f7403
X-Google-Attributes: gid1011f8,public
X-Google-Thread: 10d4ba,44c9aa94f48f7403
X-Google-Attributes: gid10d4ba,public
X-Google-Thread: f9d99,44c9aa94f48f7403
X-Google-Attributes: gidf9d99,public
From: Martin Ambuhl <mambuhl@earthlink.net>
Subject: Re: C Programming : Need help please .
Date: 1999/01/18
Message-ID: <36A2D431.D11CAB41@earthlink.net>
X-Deja-AN: 433897798
Content-Transfer-Encoding: 7bit
References: <36a2cb23.0@news2.tm.net.my>
X-Accept-Language: en
X-Posted-Path-Was: not-for-mail
Content-Type: text/plain; charset=us-ascii
X-ELN-Date: 18 Jan 1999 06:27:07 GMT
X-ELN-Insert-Date: Sun Jan 17 22:35:04 1999
Organization: Nocturnal Aviation
Mime-Version: 1.0
Newsgroups: alt.comp.lang.learn.c-c++,att.lang.c++,jaring.pcbase,tmnet.communities,tmnet.support