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
 All Forums
 Origin Forum for Programming
 Forum for Origin C
 user defined types

Note: You must be registered in order to post a reply.
To register, click here. Registration is FREE!

Screensize:
UserName:
Password:
Anti-Spam Code:
Format Mode:
Format: BoldItalicizedUnderlineStrikethrough Align LeftCenteredAlign Right Horizontal Rule Insert HyperlinkUpload FileInsert Image Insert CodeInsert QuoteInsert List
   
Message:

* HTML is OFF
* Forum Code is ON
Smilies
Smile [:)] Big Smile [:D] Cool [8D] Blush [:I]
Tongue [:P] Evil [):] Wink [;)] Clown [:o)]
Black Eye [B)] Eight Ball [8] Frown [:(] Shy [8)]
Shocked [:0] Angry [:(!] Dead [xx(] Sleepy [|)]
Kisses [:X] Approve [^] Disapprove [V] Question [?]

 
Check here to subscribe to this topic.
   

T O P I C    R E V I E W
Simon.N Posted - 06/26/2007 : 09:12:57 AM
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
2   L A T E S T    R E P L I E S    (Newest First)
Simon.N Posted - 06/27/2007 : 04:17:14 AM
Hi Zachary,

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

Sincerely,

Simon.
zachary_origin Posted - 06/26/2007 : 9:45:20 PM
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.


The Origin Forum © 2020 Originlab Corporation Go To Top Of Page
Snitz Forums 2000