1. Passing NULL to a c function

------=_NextPart_000_0007_01BF8EA4.1F8D5500
        charset="iso-8859-1"
Content-Transfer-Encoding: quoted-printable

Hi All.

I have a problem with the following wrapper function for Morfit for EU


global function Morfit_engine_load_world( sequence world_file_name, =
sequence world_directory_path, sequence bitmaps_directory_path, atom =
world_mode)
    -- int Morfit_engine_load_world(char *world_file_name, char =
*world_directory_path, char *bitmaps_directory_path, =20
   --                                                        int  =
world_mode)
    return =
                       allocate_string(world_directory_path),
                       allocate_string(bitmaps_directory_path),
                       world_mode})
end function


The above function can be called something like this (and works fine) :-

 funcval =3D =
SER_DEFINED_BEHAVIOR)


The problem I have is that I need to call it like this :-

Morfit_engine_load_world(NULL,NULL,NULL, EDITOR_MODE);  <-- the way you =
could call it in C=20

My question is how can I pass the "NULL" pointers using the wrapper. Am =
I going to have to do a test and have a function call with the =
allocate_string stuff and then another function call for the NULL's?? =
(perhaps test the sequences for an empty sequence or something?). Or is =
there a "NULL" character I can pass.....??=20

This is beyond my C knowledge. Any ideas would be greatly appreciated.

Mark Brown

mabrown at senet.com.au
=20

------=_NextPart_000_0007_01BF8EA4.1F8D5500
        charset="iso-8859-1"
Content-Transfer-Encoding: quoted-printable

<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.0 Transitional//EN">
<HTML><HEAD>
<META content=3D"text/html; charset=3Diso-8859-1" =
http-equiv=3DContent-Type>
<META content=3D"MSHTML 5.00.2314.1000" name=3DGENERATOR>
<STYLE></STYLE>
</HEAD>
<BODY bgColor=3D#ffffff>
<DIV><FONT size=3D2>Hi All.</FONT></DIV>
<DIV>&nbsp;</DIV>
<DIV><FONT size=3D2>I have a problem with the following wrapper function =
for=20
Morfit for EU</FONT></DIV>
<DIV>&nbsp;</DIV>
<DIV>&nbsp;</DIV>
<DIV><FONT size=3D2>global function Morfit_engine_load_world( sequence=20
world_file_name, sequence world_directory_path, sequence =
bitmaps_directory_path,=20
atom world_mode)<BR>&nbsp;&nbsp;&nbsp; -- int =
Morfit_engine_load_world(char=20
*world_file_name, char *world_directory_path, char=20
*bitmaps_directory_path,&nbsp; </FONT></DIV>
<DIV><FONT size=3D2>&nbsp;&nbsp;=20
bsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;=20
int&nbsp;&nbsp;world_mode)<BR>&nbsp;&nbsp;&nbsp; return=20
bsp;&nbsp;&nbsp;&nbsp;&nbsp;=20
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;=20
world_mode})<BR>end function</FONT></DIV>
<DIV>&nbsp;</DIV>
<DIV>&nbsp;</DIV>
<DIV><FONT size=3D2>The above function can be called something like this =
(and=20
works fine) :-</FONT></DIV>
<DIV>&nbsp;</DIV>
<DIV><FONT size=3D2>&nbsp;funcval =3D=20
SER_DEFINED_BEHAVIOR)</FONT></DIV>
<DIV>&nbsp;</DIV>
<DIV>&nbsp;</DIV>
<DIV><FONT size=3D2>The problem I have is that I need to call it like =
this=20
:-</FONT></DIV>
<DIV>&nbsp;</DIV>
<DIV><FONT size=3D2>Morfit_engine_load_world(NULL,NULL,NULL, =
EDITOR_MODE);&nbsp;=20
&lt;-- the way you could call it in C </FONT></DIV>
<DIV>&nbsp;</DIV>
<DIV><FONT size=3D2>My question is how can I pass the "NULL" pointers =
using the=20
wrapper. Am I going to have to do a test and have a function call with =
the=20
allocate_string stuff and then another function call for the NULL's?? =
(perhaps=20
test the sequences for an empty sequence or something?). Or is there a =
"NULL"=20
character I can pass.....?? </FONT></DIV>
<DIV><FONT size=3D2></FONT>&nbsp;</DIV>
<DIV><FONT size=3D2>This is beyond my C knowledge. Any ideas would be =
greatly=20
appreciated.</FONT></DIV>
<DIV>&nbsp;</DIV>
<DIV><FONT size=3D2>Mark Brown</FONT></DIV>
<DIV>&nbsp;</DIV>
<DIV><FONT size=3D2><A=20
>

------=_NextPart_000_0007_01BF8EA4.1F8D5500--

new topic     » topic index » view message » categorize

2. Re: Passing NULL to a c function

------=_NextPart_000_0021_01BF8EB1.90C8D660
        charset="iso-8859-1"
Content-Transfer-Encoding: quoted-printable

Hi All.

Regarding the NULL pointer problem I've solved it this way.

global function Morfit_engine_load_world( sequence world_file_name, =
sequence world_directory_path, sequence bitmaps_directory_path, atom =
world_mode)
    -- int Morfit_engine_load_world(char *world_file_name, char =
*world_directory_path, char *bitmaps_directory_path, int world_mode)
    atom world_file_name_ptr,
         world_directory_path_ptr,
         bitmaps_directory_path_ptr

    if length(world_file_name) !=3D 0 then
        world_file_name_ptr =3D allocate_string(world_file_name)
    else
        -- zero length sequence
        world_file_name_ptr =3D NULL
    end if

    if length(world_directory_path) !=3D 0 then
        world_directory_path_ptr =3D =
allocate_string(world_directory_path)
    else
        -- zero length sequence
        world_directory_path_ptr =3D NULL
    end if

    if length(bitmaps_directory_path) !=3D 0 then
        bitmaps_directory_path_ptr =3D =
allocate_string(bitmaps_directory_path)
    else
        -- zero length sequence
        bitmaps_directory_path_ptr =3D NULL
    end if

    return c_func(xMorfit_engine_load_world,{ world_file_name_ptr, =
world_directory_path_ptr, bitmaps_directory_path_ptr, world_mode} )
end function


The above works but if anyone can think of a better/neater way I'd be =
pleased to see it.

Cheers

Mark

------=_NextPart_000_0021_01BF8EB1.90C8D660
        charset="iso-8859-1"
Content-Transfer-Encoding: quoted-printable

<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.0 Transitional//EN">
<HTML><HEAD>
<META content=3D"text/html; charset=3Diso-8859-1" =
http-equiv=3DContent-Type>
<META content=3D"MSHTML 5.00.2314.1000" name=3DGENERATOR>
<STYLE></STYLE>
</HEAD>
<BODY bgColor=3D#ffffff>
<DIV><FONT size=3D2>Hi All.</FONT></DIV>
<DIV>&nbsp;</DIV>
<DIV><FONT size=3D2>Regarding the NULL pointer problem I've solved it =
this=20
way.</FONT></DIV>
<DIV>&nbsp;</DIV>
<DIV><FONT size=3D2>global function Morfit_engine_load_world( sequence=20
world_file_name, sequence world_directory_path, sequence =
bitmaps_directory_path,=20
atom world_mode)<BR>&nbsp;&nbsp;&nbsp; -- int =
Morfit_engine_load_world(char=20
*world_file_name, char *world_directory_path, char =
*bitmaps_directory_path, int=20
world_mode)<BR>&nbsp;&nbsp;&nbsp; atom=20
world_file_name_ptr,<BR>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; =

bsp;=20
bitmaps_directory_path_ptr</FONT></DIV>
<DIV>&nbsp;</DIV>
<DIV><FONT size=3D2>&nbsp;&nbsp;&nbsp; if length(world_file_name) !=3D 0 =

then<BR>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; world_file_name_ptr =
=3D=20
else<BR>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; -- zero length=20
sequence<BR>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; =
world_file_name_ptr =3D=20
NULL<BR>&nbsp;&nbsp;&nbsp; end if</FONT></DIV>
<DIV>&nbsp;</DIV>
<DIV><FONT size=3D2>&nbsp;&nbsp;&nbsp; if length(world_directory_path) =
!=3D 0=20
then<BR>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; =
world_directory_path_ptr =3D=20
else<BR>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; -- zero length=20
sequence<BR>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; =
world_directory_path_ptr=20
=3D NULL<BR>&nbsp;&nbsp;&nbsp; end if</FONT></DIV>
<DIV>&nbsp;</DIV>
<DIV><FONT size=3D2>&nbsp;&nbsp;&nbsp; if length(bitmaps_directory_path) =
!=3D 0=20
then<BR>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; =
bitmaps_directory_path_ptr =3D=20
else<BR>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; -- zero length=20
bitmaps_directory_path_ptr =3D NULL<BR>&nbsp;&nbsp;&nbsp; end =
if</FONT></DIV>
<DIV>&nbsp;</DIV>
<DIV><FONT size=3D2>&nbsp;&nbsp;&nbsp; return =
c_func(xMorfit_engine_load_world,{=20
world_file_name_ptr, world_directory_path_ptr, =
bitmaps_directory_path_ptr,=20
world_mode} )<BR>end function</FONT></DIV>
<DIV>&nbsp;</DIV>
<DIV>&nbsp;</DIV>
<DIV><FONT size=3D2>The above works but if anyone can think of a =
better/neater way=20
I'd be pleased to see it.</FONT></DIV>
<DIV>&nbsp;</DIV>
<DIV><FONT size=3D2>Cheers</FONT></DIV>
<DIV>&nbsp;</DIV>

------=_NextPart_000_0021_01BF8EB1.90C8D660--

new topic     » goto parent     » topic index » view message » categorize

3. Re: Passing NULL to a c function

Hello,
        Here is an explanation of : What is NULL?

It is a symbolic constant (atually it's not, but don't worry) to
        indicate an impossible pointer.

On most machines, and under most OS'es the first word of a processes
        address is part of
reserved memory, therefore a process can never have data there. So address 0 is
an
impossible place to have data.

So C and C++ define an invalid pointer as 0. NULL is just a more
        expressive way of
writing it. For example

        if( avar != NULL ) {

will make most C/C++ programmers think avar is a pointer. Where as with

        if( avar != 0 ) {

avar could be of any type. So I recommend using NULL.

However as NULL is not an official part of C++ Bjarne Stroustop (Spelling?)
recomends you
use 0.

It is defined in the header file <stddef.h>
-------------------------
Sincerely,
Mathew Hounsell

mat.hounsell at excite.com

new topic     » goto parent     » topic index » view message » categorize

Search



Quick Links

User menu

Not signed in.

Misc Menu