[m-users.] C compiler error

Volker Wysk post at volker-wysk.de
Tue Feb 28 04:26:01 AEDT 2023


Am Dienstag, dem 28.02.2023 um 04:13 +1100 schrieb Zoltan Somogyi:
> 
> On Mon, 27 Feb 2023 18:05:09 +0100, Volker Wysk <post at volker-wysk.de> 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.

Oops...

> 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.

Do you mean this:

MR_BEGIN_MODULE(mq_module0)
	MR_init_entry1(mq__setup_mqs_5_0);
	MR_INIT_PROC_LAYOUT_ADDR(mercury__mq__setup_mqs_5_0);
	MR_init_label6(mq__setup_mqs_5_0, 2,5,14,3,8,10)
MR_BEGIN_CODE

There is no other definition of mq_module0.

null_to_empty isn't unrelated. There is the line "In function
‘null_to_empty’:" C compiler output.


Cheers,
Volker
-------------- next part --------------
A non-text attachment was scrubbed...
Name: signature.asc
Type: application/pgp-signature
Size: 833 bytes
Desc: This is a digitally signed message part
URL: <http://lists.mercurylang.org/archives/users/attachments/20230227/b9e058cc/attachment.sig>


More information about the users mailing list