Re: Passing NULL to a c function

new topic     » goto parent     » topic index » view thread      » older message » newer message

------=_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 thread      » older message » newer message

Search



Quick Links

User menu

Not signed in.

Misc Menu