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
 user defined types
 New Topic  Reply to Topic
 Printer Friendly
Author Previous Topic Topic Next Topic Lock Topic Edit Topic Delete Topic New Topic Reply to Topic

Simon.N

France
Posts

Posted - 06/26/2007 :  09:12:57 AM  Show Profile  Edit Topic  Reply with Quote  View user's IP address  Delete Topic
Origin Version (Select Help-->About Origin): 7 SR2
Operating System: windows vista

Hello,

I try to create a list of structure 'cell' which contains a pointer to the next cell, and a pointer to a structure 'my_struct'.

here's a part of my code:

struct cell{
struct my_struct * sample;
struct cell * next_cell;
};

//typedef struct cell my_cell;

[...]
void function()
{
...
struct cell * liste_nouveau;
//my_cell * liste_nouveau;
...
liste_nouveau = (struct cell*)malloc(sizeof(struct cell));
//liste_nouveau = (my_cell*)malloc(sizeof(my_cell));
...
}


When compiling, i get the following error about the line with the malloc : "error, invalid explicit cast";

And if I use the commented lines, an error message warns me that i cannot add user defined type (because of the use of typedef)

My first thought is that it is an unsupported function of OriginC. However, if I'm wrong, and/or if there is a way to do what my piece of code is supposed to do, I would appreciate you tell me.

thanks.

Simon Nicolas

zachary_origin

China
Posts

Posted - 06/26/2007 :  9:45:20 PM  Show Profile  Edit Reply  Reply with Quote  View user's IP address  Delete Reply
Hi,

As for as I know, malloc is not supported in Origin C.

As for the structure you need, maybe you can use a group of vectors.
For example:

struct my_struct
{
int ID;
string name;
int age;
double salary;
};


you can define the vectors as:

vector <int> ID;
vector <string> name;
vector <int> age;
vector salary;
int nSize = 10;
ID.SetSize(nSize);
//... name, age, salary .SetSize()
int nIter = 0;
nIter = nIter + 1; // equivalent to liste_nouveau = liste_nouveau->next_cell;


As the size and elements of a vector can be changed dynamcally, the linked list can be simulated with the vectors.

Go to Top of Page

Simon.N

France
Posts

Posted - 06/27/2007 :  04:17:14 AM  Show Profile  Edit Reply  Reply with Quote  View user's IP address  Delete Reply
Hi Zachary,

thanks you for your tip, i will try it immediately :)

Sincerely,

Simon.
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