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 - [Question] Pointer to Struct

[Question] Pointer to Struct

Discuss PocketC for CE (including Desktop Edition)

Postby David on Mon Jun 04, 2001 12:51 pm

Does the current version of PocketC support pointer to struct?
I've tried the following codes in my v3 compiler but it seems not work:
(The compiler always shows error when i built these codes)

#define NUM_OF_PEOPLE 10
#define SHOWCONSOLE showconsole()

pointer myptr;

struct info
{
int age;
int sex;
};

struct info name;

name names[NUM_OF_PEOPLE];

myptr=&names;

main ()
{
int i;
for(i=0;i<NUM_OF_PEOPLE;i++)
{
putsl((*myptr[i].age));
putsl((*myptr[i].sex));
}

SHOWCONSOLE;
}

Is there anything wrong in these codes?Or just a bug in the PocketC?

-David
David
 
Posts: 26
Joined: Sat Jun 02, 2001 1:14 pm

Postby darwin on Wed Jun 06, 2001 12:46 pm

<h3>hi</h3>
<p>I think structs cannot be referenced right now - BTW C++ standard to access struct members in pointers look like that:</p>
<b>pointer</b> p;
p=&Yourstruct;
putsl(*p->YourVariable);
<p> Iam not sure if this is correct, but it looks like that.<br>
As far as I know structs can't be used in function's parameters what makes them sadly useless :(
</p>

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

Postby David on Wed Jun 06, 2001 10:56 pm

That's too bad:(
anyway thanks for your help darwin
-David
David
 
Posts: 26
Joined: Sat Jun 02, 2001 1:14 pm

Postby olegyk on Sun Jun 10, 2001 3:16 am

This works in v3:

<pre>#define N 5
struct S { int x; string s; };


process(struct S& p) {
putsl(p.s+": "+p.x);
}


main() {
struct S a[N]; int i;
for(i=N;i--;0) {
a[i].x=i*i;
a[i].s="<"+i+">";
}
for(i=N;i--;0)
process(a[i]);
clearg(); showconsole(); devicesip(0);
}
</pre>

Output:

<pre><4>: 16
<3>: 9
<2>: 4
<1>: 1
<0>: 0
</pre>
olegyk
 
Posts: 6
Joined: Thu May 03, 2001 5:00 pm

Postby guy on Tue Jun 12, 2001 9:02 am

It looks like the non-reference syntax could be made to work really easily as well if Kevin provided a mechanism for defining the type of pointers.

The only problem that there seems to be with using the -> syntax is that there's no way of defining what type of struct the pointer is addressing so that the field can be located in the struct.

To be really useful, the code has to work with malloced data, not just with variables declared with type "struct something".


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 cao on Wed Jun 13, 2001 2:42 am

This question has been asked over and over again. :-)
The language doesnot support that.
cao
 
Posts: 60
Joined: Tue Dec 05, 2000 4:11 am
Location: USA

Postby Joe on Mon Jun 18, 2001 12:58 am

Hi Kevin,

How about pointer to a function where the function parameter is a structure?

For example

struct point
{
int x;
int y;
};

func(struct point P)
{
return (P.x + P.y); // (note: there is a plus sign between P.x and P.y
}

main()
{
struct point P;
pointer ptr;
ptr=func;
P.x=10; P.y = 20;
putsl(func(P)); // work fine
putsl((*ptr)(P));// built successfully, but "runtime error at 10 Load"
showconsole();
}
Joe
 
Posts: 4
Joined: Mon Jun 18, 2001 12:14 am


Return to PocketC for CE

Who is online

Users browsing this forum: No registered users and 2 guests

cron