The Origin Forum
File Exchange
Try Origin for Free
The Origin Forum
Home | Profile | Register | Active Topics | Members | Search | FAQ | Send File to Tech support
Username:
Password:
Save Password
Forgot your Password? | Admin Options

 All Forums
 Origin Forum for Programming
 Forum for Origin C
 (Type *) malloc(sizeof(Type))
 New Topic  Reply to Topic
 Printer Friendly
Author Previous Topic Topic Next Topic Lock Topic Edit Topic Delete Topic New Topic Reply to Topic

kid

USA
20 Posts

Posted - 07/21/2002 :  5:43:11 PM  Show Profile  Edit Topic  Reply with Quote  View user's IP address  Delete Topic
What are the restrictions of the OriginC compiler on the malloc function. I've been trying to do a link list using this code
#include <origin.h>

struct spacePoints {
int index;
int xPos;
int yPos;
int zPos;
spacePoints *next;
};

void tryThisOne(void) {

spacePoints start, *node;
start.next = NULL;
node = &start;

for(int count = 0; count < 3; count++) {
node->index = count;
[Line 19] node->next = (spacePoints *) malloc( sizeof(spacePoints) );
node = node->next;
node->next = NULL;
}

printf("The size of this struct is: %d\n", sizeof(spacePoints) );

return;
}

and I get a compiler error on line 19: Error, invalid explicit cast.
Is there a limitation in the OriginC compiler, or is there something wrong in my code. I know I can get around using a link list, by using a wks object, but I'll like to know if Link Lists are sported in OriginC anyway.

Alex...

lilo

Germany
2 Posts

Posted - 12/05/2002 :  09:23:36 AM  Show Profile  Edit Reply  Reply with Quote  View user's IP address  Delete Reply
I have got a similar problem. I'm trying to build a working version of
nrutils.c from numerical recipes for Origin C and I get the same error message "Error, invalid explicit cast" in the last line cited here:
 
#define NR_END 1
long nrow=nrh-nrl+1;
float **m;
m=(float**) malloc((size_t) ((nrow+NR_END)*sizeof(float*)));

I'd really be glad if someone could tell me a way round this...
Go to Top of Page

ML

USA
63 Posts

Posted - 12/06/2002 :  11:25:53 AM  Show Profile  Edit Reply  Reply with Quote  View user's IP address  Delete Reply
quote:

I have got a similar problem. I'm trying to build a working version of
nrutils.c from numerical recipes for Origin C and I get the same error message "Error, invalid explicit cast" in the last line cited here:
 
#define NR_END 1
long nrow=nrh-nrl+1;
float **m;
m=(float**) malloc((size_t) ((nrow+NR_END)*sizeof(float*)));

I'd really be glad if someone could tell me a way round this...


The support for m = (float**)malloc() will be provided in the upcoming service release.
Go to Top of Page

Frank_H

Germany
Posts

Posted - 01/10/2006 :  1:13:33 PM  Show Profile  Edit Reply  Reply with Quote  View user's IP address  Delete Reply
Is there still no typecast for structs?
Tried

Nag_Spline * spline;
spline = (Nag_Spline *) malloc(sizeof(Nag_Spline));


and got the same error as Alex (Error, invalid explicit cast) :-(

Cheers,
Frank
Go to Top of Page

easwar

USA
1965 Posts

Posted - 01/12/2006 :  09:10:35 AM  Show Profile  Edit Reply  Reply with Quote  View user's IP address  Delete Reply
Hi Frank,

This is currently not supported, but will be in the next version.

Easwar
OriginLab


Go to Top of Page
  Previous Topic Topic Next Topic Lock Topic Edit Topic Delete Topic New Topic Reply to Topic
 New Topic  Reply to Topic
 Printer Friendly
Jump To:
The Origin Forum © 2020 Originlab Corporation Go To Top Of Page
Snitz Forums 2000