LabWindows/CVI

cancel
Showing results for 
Search instead for 
Did you mean: 

NON-FATAL RUN-TIME ERROR: "Start.c", line 152, col 34, thread id 0x00000C7C: Not enough space for casting expression to 'pointer to struct'

I'm using LabWindows/CVI 8.5.
Who can tell me, what does it mean:NON-FATAL RUN-TIME ERROR:   "XXXX.c", line 152, col 34, thread id 0x00000C7C:   Not enough space for casting expression to 'pointer to struct' ?
I am trying to require a memory for my big structure with a malloc function and  i receive this error message. I can continue to run my programm, but i want to avoid this message in future. Does it mean, i have not enough stack memory for allocation or something else ? What should i do, to allocate memory without this error message?
 
Than you
0 Kudos
Message 1 of 5
(5,218 Views)

Could you post the offending code?

JR

0 Kudos
Message 2 of 5
(5,206 Views)
Here the code:
Well, the big structure Radio is realy big, is about 230 Byte in a empty state. But it does not matter, is not it? I think there is a problem with a memory reservation for a pointer for this structure.
 
struct Radio *RadioGruppen[20];  // global
...
...
...
...
void GenerateGroups(int GruppenStaerke, int GruppenIndex, int ZellenNr)
{
 int El = 0;
 
  RadioGruppen[GruppenIndex] = malloc(sizeof(RadioGruppen[GruppenIndex])); // on this line happens first time
  RadioGruppen[GruppenIndex]->ZelleNr = ZellenNr;
  RadioGruppen[GruppenIndex]->Gruppenstaerke = GruppenStaerke;
  RadioGruppen[GruppenIndex]->next = NULL;

  for(El = 1; El < GruppenStaerke; El++)
  {
   ZellenNr++;
   RadioGruppen[GruppenIndex] = AppendNewElement(RadioGruppen[GruppenIndex],ZellenNr); // in this function i create with malloc
                                                                                                           //  function new elements and
                                                                                                           // append them to the
                                                                                                           // RadioGruppen[GruppenIndex],
  }
}
 
...
...
...
the other header file:
struct Radio * AppendNewElement(struct Radio *lst, int ZNr)
{
    struct Radio *new_list_item= malloc(sizeof(new_list_item));
 struct Radio *cur= lst;       /* declare variable for parsing list */
 
 new_list_item->ZelleNr = ZNr;/* assign elem to list item*/
 new_list_item->next = NULL;/* thereisno successorto thenewelement*/
 
 if(lst==NULL)               /* if list empty*/
 {
  return new_list_item;/* return new element*/
 }
 while(cur->next!= NULL)/* otherwise parse list and search for last elem*/
 {
  cur=cur->next;
 }
 
 cur->next=new_list_item; /* append new element to the last element*/
 
 return lst;/* were turn the new list */
}
 
Thank you for the answer.


Message Edited by Boris1980 on 03-05-2008 08:54 AM
0 Kudos
Message 3 of 5
(5,200 Views)

I think the problem is in your malloc() statement. The item RadioGruppen[GruppenIndex] is a pointer (to Radio), so doing a sizeof on it will return 4 bytes. This is how many bytes malloc() will reserve. I suspect you intended it to allocate enough memory for an entire Radio structure. The same is true of your second malloc(), in AppendNewElement(): you are allocating memory for a pointer, not an actual structure.

JR

0 Kudos
Message 4 of 5
(5,192 Views)

Ok, i thought  about it too, but this statement occurs the same error:

struct Radio *RadioGruppen[20];  // global
struct Radio SRadio;  // global
 
RadioGruppen[GruppenIndex] = malloc(sizeof(SRadio)); // on this line happens too
 
i do not know, why i can not  allocate memory  this way.
SRadio is the structure in this case, not a pointer, so what a problem ?
 
Thank you for the answer.
0 Kudos
Message 5 of 5
(5,186 Views)