Dear Expert, I have a simple C program with 'linklist' data structure processing as below. ////////////////////////////////////// #include <stdio.h> #include <stdlib.h> typedef struct node{ unsigned int id; struct node * next; }; void main(void){ struct node * first; struct node * n; unsigned int i; printf("/////////////////\r\n"); first->next = (struct node *) malloc(sizeof(struct node) * 10); if(first->next == NULL)printf("** Not enough memory space\r\n"); printf("first->next %X\r\n",first->next); first = NULL; //no first link for(i=1;i<=10;i++){ n->id = i; n->next = first; first = n; }; while(first != NULL){ printf("n->id = %X , n->next %X\r\n",first->id,first->next); first = first->next; } free(first); } ///////////////////// When I run this program , the result is unterminate loop. But I try to test this program on Turbo C++ when including "malloc.h" , it is work and result is correct! What wrong with this codeing? Then,I wonder does C51 support link list data processing? I will looking forward your reply and thank you for all suggestion. Birdy.
Linked Lists do not inherently rely upon dynamic allocation, and can be quite useful even on an 8051; useful, maybe, efficient no. A liked list is pointer to pointer to pointer to ..... which is not candy to a '51. why malloc() is generally avoided in embedded systems have nothing to do with the 8051 architecture agreed, it should be generally avoided, just as a lot of other "standard" things this is worse in a '51 than in most. I love the '51 and it performs beautifully when used as a '51, but when somone treat is as a "small PC" it sucks because it is so good at what is is intended for. Erik