Re: [m-users.] C compiler error

"Zoltan Somogyi" <[email protected]>
Newsgroups gmane.comp.lang.mercury.general
Message-ID <[email protected]>

On Mon, 27 Feb 2023 18:05:09 +0100, Volker Wysk <[email protected]> wrote:
> I've taken a look at the mq.c file. There, mq_module0, mq_module1 and so on
> are automatically generated C functions. And their storage class is invalid.
> So this would be a Mercury compiler bug.

Only if you consider the Mercury compiler's inability to automatically fix
a bug in user-provided C code to be a bug in the Mercury compiler :-(

> Am Montag, dem 27.02.2023 um 15:49 +0100 schrieb Volker Wysk:
> > Hi.
> > 
> > I have a Mercury module with a lot of foreign C code, and I get many
> > compiler errors like this:
> > 
> > Making Mercury/os/mq.o
> > Mercury/cs/mq.c: In function ‘null_to_empty’:
> > Mercury/cs/mq.c:644:1: error: invalid storage class for function
> > ‘mq_module0’
> > Mercury/cs/mq.c:644:1: error: invalid storage class for function
> > ‘mq_module0’
> > Mercury/cs/mq.c:764:1: error: invalid storage class for function
> > ‘mq_module1’
> > Mercury/cs/mq.c:764:1: error: invalid storage class for function
> > ‘mq_module1’
> > ...
> > 
> > 
> > 
> > The function in question is this:
> > 
> > :- pragma foreign_code("C",
> > "
> >   char * null_to_empty(char * str)
> >   {
> >     if (str == 0) {
> >        MR_String str1 = MR_GC_malloc(1);
> >        *str1 = (char) 0;
> >        return str1;
> >     } else {
> >        return str;
> >     }
> > ").

The bug is in your code: the left brace that starts the C function
has no matching right brace. The C compiler complains about
the following C functions because it thinks that they are being
declared INSIDE the null_to_empty function.

In the future, when reporting a possible problem with an error message
that mentions some definitions (mq_module0 and mq_module1),
it would help if you included the CODE OF THOSE DEFINITIONS,
and not the definition of something unrelated, such as null_to_empty.

Zoltan.



_______________________________________________
users mailing list
[email protected]
https://lists.mercurylang.org/listinfo/users
lmpx.com only provides a reader for public news (NNTP) servers. It is not affiliated with the servers or forums shown here and is not responsible for the content of articles, which is written by their respective authors.