Void * Issues As Type Members And Function Return Types

Started by Peter_R, May 22, 2012, 06:08:54 PM

Previous topic - Next topic

0 Members and 1 Guest are viewing this topic.

Peter_R

Quote from: Peter_R on May 22, 2012, 09:32:12 PM
I could do something such as always using an int *. Then I could add an explicit (int *) cast as I pass objects in and an explicity (arbitraryType *) cast as I get the objects back out, but this would make the code a lot messier.
Of course it is possible that this type of casting is possible implicitly in BennuGD? I think that without the casts such statements would cause warnings/errors in C. E.g. (int *) someFloat and (float *) someInt.

SplinterGU

#16
cast between pointers are implicit...

you can do....

function my_func( pointer blah )
begin
...
end

it's valid...

sample


import "mod_say"

Function voidPtrArgFunc(pointer voidPtrArg)

Begin
// So we can see the actual parameter bound
// to the argument
say(voidPtrArg);
End

Function main()

Begin
voidPtrArgFunc(2);
voidPtrArgFunc(1);
say("Success");
End


a pointer a pointer... if you use a void * is same that you use for replace it... you can't access to members on void *, then if you pass a struct as void *, you need cast it for access to his members... then is same thing that you use a void * or a int * or a blah *
Download Lastest BennuGD Release: http://www.bennugd.org/node/2

Peter_R

Thanks, I ended up using something along the lines of the following:

#DEFINE void int

This does two things:

  • Gives a clear indication of where I should not rely on the type of variable pointed to
  • Pleases the C programmer in me :P