2 registered members (Martin_HH, TipmyPip),
1,279
guests, and 10
spiders. |
Key:
Admin,
Global Mod,
Mod
|
|
|
Pointer to pointer?
#280369
07/22/09 12:10
07/22/09 12:10
|
Joined: May 2004
Posts: 1,510 Denmark
Claus_N
OP
Serious User
|
OP
Serious User
Joined: May 2004
Posts: 1,510
Denmark
|
Hi, It seems that it is not possible to use a pointer to a pointer in Lite-C - can anyone confirm this? The manual didn't seem to say anything about it I tried testing it with this code, which resulted in a crash ("invalid arguments"):
void test(RPGItem** _temp)
{
str_cat(_temp.name,"\ntest");
}
|
|
|
Re: Pointer to pointer?
[Re: Claus_N]
#280373
07/22/09 12:34
07/22/09 12:34
|
Joined: Feb 2008
Posts: 3,232 Australia
EvilSOB
Expert
|
Expert
Joined: Feb 2008
Posts: 3,232
Australia
|
You DEFINATELY CAN use pointers to pointers (to pointers even). I use them with multi-dimensional arrays often.
Without seeing your RPGItem struct, I cant be sure, but try (in this order) str_cat(_temp->name,"\ntest"); or str_cat((_temp)->name,"\ntest"); or str_cat((*_temp)->name,"\ntest");
The "->" is required, assuming that "name" is a string pointer.
"There is no fate but what WE make." - CEO Cyberdyne Systems Corp. A8.30.5 Commercial
|
|
|
Re: Pointer to pointer?
[Re: Claus_N]
#280384
07/22/09 13:22
07/22/09 13:22
|
Joined: Feb 2008
Posts: 3,232 Australia
EvilSOB
Expert
|
Expert
Joined: Feb 2008
Posts: 3,232
Australia
|
Thats right, Ive passed pointer-to-a-pointer's that way without issue before.
Can you post the code that calls the 'test' function. And the code that builds the data too. So I can see the logic behind why you need to call it as a pointer-to-a-pointer. In case theres a bug in that somewhere...
"There is no fate but what WE make." - CEO Cyberdyne Systems Corp. A8.30.5 Commercial
|
|
|
Re: Pointer to pointer?
[Re: EvilSOB]
#280387
07/22/09 13:31
07/22/09 13:31
|
Joined: May 2004
Posts: 1,510 Denmark
Claus_N
OP
Serious User
|
OP
Serious User
Joined: May 2004
Posts: 1,510
Denmark
|
I was doing it just for testing purposes, though here's the code using the function:
// In function main
RPGItem* testItem;
testItem.type = 2;
testItem.name = testStr;
test(&testItem);
and the struct so far:
typedef struct RPGItem
{
var type;
int cellsX;
int cellsY;
BMAP* bmap;
STRING* name;
} RPGItem;
Edit: this is the first time I'm trying to use Lite-C so it wouldn't surprise me if I missed something Edit 2: I tried using a pointer-to-a-pointer of an integer instead, and it worked, so I'm probably just missing something Edit 3 : Tried this and it does work:
void test(RPGItem** _temp)
{
(**_temp).type = 2;
}
Last edited by Claus_N; 07/22/09 13:40.
|
|
|
Re: Pointer to pointer?
[Re: Claus_N]
#280394
07/22/09 14:04
07/22/09 14:04
|
Joined: Feb 2008
Posts: 3,232 Australia
EvilSOB
Expert
|
Expert
Joined: Feb 2008
Posts: 3,232
Australia
|
With what you have, you dont need a pointer-to-a-pointer. (all below code is tested)
void _test(RPGItem *_temp)
{
str_cat(_temp->name,"\ntest");
}
// In function main
RPGItem testItem;
testItem.type = 2;
testItem.name = str_create(_chr(testStr));
_test(&testItem);
Unless your items are going into an array like this....
void _test(RPGItem *_temp)
{
str_cat(_temp->name,"\ntest");
}
// In function main
RPGItem *testItem = malloc(sizeof(RPGItem)*20);
var i; for(i=0; i<20; i++) { memset(testItem[i],0,sizeof(RPGItem)); }
testItem[0].type = 2;
testItem[0].name = str_create(_chr(testStr));
_test(&testItem[0]);
"There is no fate but what WE make." - CEO Cyberdyne Systems Corp. A8.30.5 Commercial
|
|
|
Re: Pointer to pointer?
[Re: EvilSOB]
#280398
07/22/09 14:19
07/22/09 14:19
|
Joined: May 2004
Posts: 1,510 Denmark
Claus_N
OP
Serious User
|
OP
Serious User
Joined: May 2004
Posts: 1,510
Denmark
|
I was just testing whether it was possible in Lite-C, as I would be using it later on while writing my inventory system (I'm re-writing my old c-script inventory in Lite-C )
|
|
|
Re: Pointer to pointer?
[Re: Claus_N]
#280400
07/22/09 14:21
07/22/09 14:21
|
Joined: Feb 2008
Posts: 3,232 Australia
EvilSOB
Expert
|
Expert
Joined: Feb 2008
Posts: 3,232
Australia
|
Kewl, would be nice to see. Public use? Or trade secret code? (just curious)
"There is no fate but what WE make." - CEO Cyberdyne Systems Corp. A8.30.5 Commercial
|
|
|
Re: Pointer to pointer?
[Re: EvilSOB]
#280406
07/22/09 14:33
07/22/09 14:33
|
Joined: May 2004
Posts: 1,510 Denmark
Claus_N
OP
Serious User
|
OP
Serious User
Joined: May 2004
Posts: 1,510
Denmark
|
For a small RPG project ( http://www.zofteyez.dk/azarinath/ ). I'll probably make an inventory like this for "public use" later, but it depends on the amount of homework :P
Last edited by Claus_N; 07/22/09 14:33. Reason: typo
|
|
|
|