[m-users.] Compiler warning in my readdir.m
Volker Wysk
post at volker-wysk.de
Mon Oct 14 16:09:27 AEDT 2019
Am Montag, den 14.10.2019, 15:47 +1100 schrieb Peter Wang:
> > > Changing the 'Entry =' line to 'Entry = (char*) \"\"' avoids the
> > > warning message. I guess it's not an error, but I'm not
> > > completely
> > > sure. I'm not experienced with the foreign language interface
> > > (yet).
> > > Maybe it's the type of "Entry" should be "char * const", rahter
> > > than
> > > "char *".
> > >
> >
> > A string literal like "" is going to be in read-only memory, so the
> > const stuff helps slightly to prevent accidental writing to it.
> > What you're doing though is pretty weird: returning a string just
> > so that Mercury can test for that string.
> >
> > Probably you arrived at this design because per the pred
> > declaration you're obliged to return a string even when there's no
> > useful string to return. What you can do though, is just not set
> > Entry at all (untested):
>
> You should assign valid values to all output variables, in particular
> because the debugger may try to print the values out. You can set a
> variable to a constant string like this:
>
> Entry = MR_make_string_const(""")
I see I need to study the foreign language interface. I've just tried
it out, and it compiled (except for that warning) and worked. So I
thought it would be okay.
Sorry for the tinkering. :)
Cheers
Volker
More information about the users
mailing list