Vote count:
0
#include <stdio.h>
#include <stdlib.h>
/i am writing a code for a compiler for toy language.this is a snipet of code . in main there are two functions createlist and node .when one is commented other one works fine but together it shows a error which i dont understand.any help is appreciated/
struct node { //declaration for node
int tokenno;
struct node * next ;
};
struct node * newnode(int a) // to create a new node
{
struct node * new1 = (struct node *)malloc(sizeof(struct node));
printf("\n malloc sucees");
(*new1).tokenno = a ;
(*new1).next = NULL ;
printf("\new node sucess\n");
return (new1);
};
struct firstlist{
int size ;
struct node * list[10];
};
typedef struct firstlist * plist;
plist createlist(){ //fun to create a first list
int i ;
plist p = (plist) malloc(sizeof(struct firstlist));
(*p).size = 10 ;
for(i = 0 ; i <=10;i++){ //initializing list[i] to NULL
(*p).list[i] = NULL ;
}
printf("\n created sucessfully");
return p;
}
int main(){
plist p ;
//p = createlist(); // if you comment createlist the new node works fine
//getfirstset(p);
//insert(1,5,p);
newnode(2); // if you comment newnode then createlist works fine but together it shows the following error
/*a.out: malloc.c:2372: sysmalloc: Assertion `(old_top == (((mbinptr) (((char *) &((av)->bins[((1) - 1) * 2])) - __builtin_offsetof (struct malloc_chunk, fd))))
&& old_size == 0) || ((unsigned long) (old_size) >= (unsigned long)((((__builtin_offsetof (struct malloc_chunk, fd_nextsize))+((2 *(sizeof(size_t))) - 1))
& ~((2 *(sizeof(size_t))) - 1))) && ((old_top)->size & 0x1) && ((unsigned long) old_end & pagemask) == 0)' failed.
created sucessfullyAborted*/
}
asked 1 min ago
regarding pointers and malloc errors
Aucun commentaire:
Enregistrer un commentaire