Deprecated: preg_replace(): The /e modifier is deprecated, use preg_replace_callback instead in /home/jerdew5/orbworks.com/forum/includes/bbcode.php on line 472

Deprecated: preg_replace(): The /e modifier is deprecated, use preg_replace_callback instead in /home/jerdew5/orbworks.com/forum/includes/bbcode.php on line 472

Deprecated: preg_replace(): The /e modifier is deprecated, use preg_replace_callback instead in /home/jerdew5/orbworks.com/forum/includes/bbcode.php on line 472

Deprecated: preg_replace(): The /e modifier is deprecated, use preg_replace_callback instead in /home/jerdew5/orbworks.com/forum/includes/bbcode.php on line 472

Deprecated: preg_replace(): The /e modifier is deprecated, use preg_replace_callback instead in /home/jerdew5/orbworks.com/forum/includes/bbcode.php on line 472

Deprecated: preg_replace(): The /e modifier is deprecated, use preg_replace_callback instead in /home/jerdew5/orbworks.com/forum/includes/bbcode.php on line 472

Deprecated: preg_replace(): The /e modifier is deprecated, use preg_replace_callback instead in /home/jerdew5/orbworks.com/forum/includes/bbcode.php on line 472

Deprecated: preg_replace(): The /e modifier is deprecated, use preg_replace_callback instead in /home/jerdew5/orbworks.com/forum/includes/bbcode.php on line 472

Deprecated: preg_replace(): The /e modifier is deprecated, use preg_replace_callback instead in /home/jerdew5/orbworks.com/forum/includes/bbcode.php on line 472

Deprecated: preg_replace(): The /e modifier is deprecated, use preg_replace_callback instead in /home/jerdew5/orbworks.com/forum/includes/bbcode.php on line 472

Deprecated: preg_replace(): The /e modifier is deprecated, use preg_replace_callback instead in /home/jerdew5/orbworks.com/forum/includes/bbcode.php on line 472

Deprecated: preg_replace(): The /e modifier is deprecated, use preg_replace_callback instead in /home/jerdew5/orbworks.com/forum/includes/bbcode.php on line 472

Deprecated: preg_replace(): The /e modifier is deprecated, use preg_replace_callback instead in /home/jerdew5/orbworks.com/forum/includes/bbcode.php on line 472

Deprecated: preg_replace(): The /e modifier is deprecated, use preg_replace_callback instead in /home/jerdew5/orbworks.com/forum/includes/bbcode.php on line 472

Deprecated: preg_replace(): The /e modifier is deprecated, use preg_replace_callback instead in /home/jerdew5/orbworks.com/forum/includes/bbcode.php on line 472

Deprecated: preg_replace(): The /e modifier is deprecated, use preg_replace_callback instead in /home/jerdew5/orbworks.com/forum/includes/bbcode.php on line 472

Deprecated: preg_replace(): The /e modifier is deprecated, use preg_replace_callback instead in /home/jerdew5/orbworks.com/forum/includes/bbcode.php on line 472

Deprecated: preg_replace(): The /e modifier is deprecated, use preg_replace_callback instead in /home/jerdew5/orbworks.com/forum/includes/bbcode.php on line 472

Deprecated: preg_replace(): The /e modifier is deprecated, use preg_replace_callback instead in /home/jerdew5/orbworks.com/forum/includes/bbcode.php on line 472

Deprecated: preg_replace(): The /e modifier is deprecated, use preg_replace_callback instead in /home/jerdew5/orbworks.com/forum/includes/bbcode.php on line 472

Deprecated: preg_replace(): The /e modifier is deprecated, use preg_replace_callback instead in /home/jerdew5/orbworks.com/forum/includes/bbcode.php on line 472

Deprecated: preg_replace(): The /e modifier is deprecated, use preg_replace_callback instead in /home/jerdew5/orbworks.com/forum/includes/bbcode.php on line 472

Deprecated: preg_replace(): The /e modifier is deprecated, use preg_replace_callback instead in /home/jerdew5/orbworks.com/forum/includes/bbcode.php on line 472

Deprecated: preg_replace(): The /e modifier is deprecated, use preg_replace_callback instead in /home/jerdew5/orbworks.com/forum/includes/bbcode.php on line 472

Deprecated: preg_replace(): The /e modifier is deprecated, use preg_replace_callback instead in /home/jerdew5/orbworks.com/forum/includes/bbcode.php on line 472

Deprecated: preg_replace(): The /e modifier is deprecated, use preg_replace_callback instead in /home/jerdew5/orbworks.com/forum/includes/bbcode.php on line 472
[phpBB Debug] PHP Notice: in file /includes/functions.php on line 3368: Cannot modify header information - headers already sent by (output started at /includes/bbcode.php:472)
[phpBB Debug] PHP Notice: in file /includes/functions.php on line 3370: Cannot modify header information - headers already sent by (output started at /includes/bbcode.php:472)
[phpBB Debug] PHP Notice: in file /includes/functions.php on line 3371: Cannot modify header information - headers already sent by (output started at /includes/bbcode.php:472)
[phpBB Debug] PHP Notice: in file /includes/functions.php on line 3372: Cannot modify header information - headers already sent by (output started at /includes/bbcode.php:472)
OrbWorks Community Forum • View topic - Structs in PocketC?

Structs in PocketC?

Discuss PocketC for CE (including Desktop Edition)

Postby psychic_treason on Fri Feb 02, 2001 11:45 am

Okay, I know I have posted a lot of stuff on here recently, apologies to all the people that are bored with me now....

Anyway, can you create new types through STRUCTS or something similar in PocketC?

Any ideas would be cool.
psychic_treason
 
Posts: 12
Joined: Thu Feb 01, 2001 12:52 pm
Location: United Kingdom

Postby Justinespinosa on Fri Feb 02, 2001 4:00 pm

well, It's a bit hardier.
You can do that with structured pointers.

I don't know if you know how to use pointers, but with them , you can create stcuctured array of variable.
Darwin has explained it to me. That's like a tree view.
You can create a variable that have a lot of values of different types in it.

so this:

<pre id=code><font face=courier size=2 id=code>
pointer p;

p = malloc(10);

p[0] = malloc(5);

settype(p[0],5,'s'); // sets the type of the values in p[0]


</font id=code></pre id=code>

will create a struct like this in the variable p:

p = adress were p is stored
+-p[0] = adress were p[0] is stored
| +-p[0][0] = string value
| +-p[0][1] = string value
| +-p[0][2] = string value
| +-p[0][3] = string value
| +-p[0][4] = string value
+-p[1] = int value
+-p[2] = int value
+-p[3] = int value
+-p[4] = int value

to assign a value just do p[0][2] = "string";

to pass the variable to a function, just use the adress were the variable is stored.
(ex: Func_Do(pointer p) )

to pass the variable form a function, return the adress
(ex: <pre id=code><font face=courier size=2 id=code>
Func_New(parameters){
pointer p; // define a new pointer

p = malloc(...)

// assign parameters to pointer.

return p;
}
main(){
pointer Var:

Var = Func_New(parameters);
}
</font id=code></pre id=code>

Before re-allocing a pointer, you must free it with free(pointer p)

like this

p = malloc(10);

p[0] = malloc(5);

p[0][0] = malloc(2);

free(p[0][0]); // free last tree levels first
free(p[0]);
free(p);


I hope this will help you. if you have questions or problems, just send me a mail or post on my forum on http://www.outs4pda.cjb.net

J.Espinosa

OUTS Softwares
J.Espinosa

OUTS Softwares
Justinespinosa
 
Posts: 156
Joined: Wed Dec 06, 2000 2:30 pm
Location: Switzerland

Postby psychic_treason on Sat Feb 03, 2001 1:41 pm

Thanks for the help Justin. Much appreciated.

This seems like a very convoluted way to build structures, but it seems that it will work reasonably well (slight concern with efficiency of larger structs). I'm still flipping my brain over from normal c/c++ into the whole pocketC thing.

Is there a place to request additions to the next version of the compiler/run time and possibly help writing it? It would be nice to see better support for things like structs, screen surfaces etc.

Regards,
Andrew
psychic_treason
 
Posts: 12
Joined: Thu Feb 01, 2001 12:52 pm
Location: United Kingdom

Postby guy on Tue Feb 06, 2001 8:51 am

PocketC (V3) supports structs, but not accessing fields in them through pointers.

struct mystruct {
int i ;
pointer p ;
char c ;
} ;

struct mystruct s ;

s.i = 1;
s.p = &something ;
s.c = 'a' ;

// All that works

pointer p ;

p = &s ;

p->i = 1;

// Doesn't work. PocketC can't resolve the offset.


Guy
Guy
[url]mailto:pcform@pcform.net[/url]
http://www.pcform.net
PocketC CE API interface: http://www.networkdynamics.net/PCForm.html#library
PCForm and CE API forum: http://www.networkdynamics.net/forum
guy
 
Posts: 879
Joined: Thu Dec 07, 2000 8:58 am
Location: United Kingdom

Postby darwin on Tue Feb 06, 2001 11:09 am

Cool, I didn't know that!
Where was it mentioned that V3 support ALREADY structs?

http://www.strange-phenomenom.de/newp/pocketc.htm
darwin
 
Posts: 71
Joined: Tue Dec 05, 2000 12:04 pm
Location: Germany

Postby psychic_treason on Tue Feb 06, 2001 2:34 pm

Hey Justin and Guy, thanks for the help on this one. The stuff about the struct support was exactly what I was after.

Now I've got a new problem and I think it is just because I am being dim.

Here's the deal. I've set up a struct with all the bits in it that I want.

eg: struct node {
string key;
pointer lchild;
pointer rchild;
};

A binary tree type thing yeah? Okay, now obviously if I want to create a tree I have to call a function that creates each of the nodes and passes back something to the calling function. Here's a copy of what I'm doing:

pointer createGenNode(string key) {
// this function takes a string and creates a generic node, passing a pointer back to the
// caller with a reference to it.

struct nodeode newNode;

newNode.key = key;
newNode.lchild = NULL;
newNode.rchild = NULL;

//putsl(newNode.key);

return &newNode;

}

So I'm trying to pass back a reference to the node I just created. However I realised that I can't do this as I'm actually referencing a local variable which is destroyed after the function exits! Damn...

Next I tried to pass the structure back but that causes stack corruption. Any ideas?

I'd really like to implement a nice BTree for something I'm working on...

Regards,
Andrew


-- http://www.talent2.net --
psychic_treason
 
Posts: 12
Joined: Thu Feb 01, 2001 12:52 pm
Location: United Kingdom

Postby guy on Wed Feb 07, 2001 8:06 am

I suggest that you look at the dynamic linked list/tree library rather than reinventing the wheel from scratch. It supports trees of lists, with various list and tree manipulation functions as well as node constructors and destructors and a tree walk with node entry and exit callbacks to functions that you supply.

The only thing it's really missing at the moment is a user callback for comparison so that entries can be sorted as they are inserted.

The latest version of the library in Unicode for the device compiler is at:

http://www.networkdynamics.net/linklist.zip

There is an updated version in ASCII with some additional features at:

http://www.networkdynamics.net/linklist_ascii.zip

If I have time today I'll add an insert sorted function to the ASCII version and update the library on the server.


Guy
Guy
[url]mailto:pcform@pcform.net[/url]
http://www.pcform.net
PocketC CE API interface: http://www.networkdynamics.net/PCForm.html#library
PCForm and CE API forum: http://www.networkdynamics.net/forum
guy
 
Posts: 879
Joined: Thu Dec 07, 2000 8:58 am
Location: United Kingdom

Postby darwin on Fri Feb 09, 2001 10:58 am

If I cannot pass a struct to a function as an argument (am I wrong?), if I can't use it as a pointer - what are the structs good for?

http://www.strange-phenomenom.de/newp/pocketc.htm
darwin
 
Posts: 71
Joined: Tue Dec 05, 2000 12:04 pm
Location: Germany

Postby guy on Fri Feb 09, 2001 11:16 am

I agree.

Kevin said something to me about being able to pass structs around. Perhaps you can use them in function arguments.

Until I can use pointers to them so that I can malloc() them then they are not much use to me either. I also need a sizeof() function.

I don't know how Kevin will resolve the issue of addressing fields within structs through a pointer. Because pointers are untyped then finding the field name would be difficult:

struct first {
int i ;
int j ;
} ;

struct second {
int j ;
int i ;
}

pointer p ;

p = SomeFunctionReturningAPointer() ;

p->i = 2 ;

// How does PocketC know which "i" it is?
// Could be either field 1 or field 2

Guy


Edited by - guy on 02/09/2001 05:30:42
Guy
[url]mailto:pcform@pcform.net[/url]
http://www.pcform.net
PocketC CE API interface: http://www.networkdynamics.net/PCForm.html#library
PCForm and CE API forum: http://www.networkdynamics.net/forum
guy
 
Posts: 879
Joined: Thu Dec 07, 2000 8:58 am
Location: United Kingdom

Postby psychic_treason on Fri Feb 09, 2001 12:08 pm

Indeed, this has been one of my biggest trials with pocketC (and no direct screen access grrrr).

I think there needs to be a concerted effort on this for the next version as it would be nice to have structs that work properly.

In the mean time, thanks for that code Guy, it worked a treat. It wasn't exactly right for what I wanted for the Binary Tree so I just took it and adapted it for my needs. I'll send you a copy if you want when I'm done so you have a specific BTree datastructure as well as a linked list one. - Very useful.

-- http://www.talent2.net --
psychic_treason
 
Posts: 12
Joined: Thu Feb 01, 2001 12:52 pm
Location: United Kingdom

Postby guy on Tue Feb 13, 2001 8:26 am

Thank you, I would be very interested in a copy.

Would you like to add your new functions to the library so that they are available to everyone?

If they are significantly different then it may be unwise to include both lots since it will bulk out callers code. The desktop version of PocketC apparently only includes functions that are called in the final app file. I understand that the new version is only single pass so may not have this optimisation.



Guy
Guy
[url]mailto:pcform@pcform.net[/url]
http://www.pcform.net
PocketC CE API interface: http://www.networkdynamics.net/PCForm.html#library
PCForm and CE API forum: http://www.networkdynamics.net/forum
guy
 
Posts: 879
Joined: Thu Dec 07, 2000 8:58 am
Location: United Kingdom

Postby guy on Tue Feb 13, 2001 8:39 am

White on lime green?!


Guy
Guy
[url]mailto:pcform@pcform.net[/url]
http://www.pcform.net
PocketC CE API interface: http://www.networkdynamics.net/PCForm.html#library
PCForm and CE API forum: http://www.networkdynamics.net/forum
guy
 
Posts: 879
Joined: Thu Dec 07, 2000 8:58 am
Location: United Kingdom

Postby psychic_treason on Wed Feb 14, 2001 10:06 am

Guy,

Some of it I modified from yours and some are new bits that are very specific to the Binary Tree ADT. I haven't quite finished it yet (I've actually *gone outside* for the last few days) but it shouldn't be much longer.

Yes Lime Green and white.... it was supposed to be fresh =) don't ask me, I just built the thing, it was my creative partner that came up with the colour scheme :P

Andrew



-- http://www.talent2.net --
psychic_treason
 
Posts: 12
Joined: Thu Feb 01, 2001 12:52 pm
Location: United Kingdom


Return to PocketC for CE

Who is online

Users browsing this forum: No registered users and 3 guests

cron