[m-dev.] diff: pragma c_code fix
Peter Ross
peter.ross at miscrit.be
Fri Nov 10 21:36:10 AEDT 2000
On Fri, Nov 10, 2000 at 04:51:32PM +1100, Fergus Henderson wrote:
> On 10-Nov-2000, Tyson Dowd <trd at cs.mu.OZ.AU> wrote:
> > On 09-Nov-2000, Peter Ross <peter.ross at miscrit.be> wrote:
> > > mercury/compiler/llds_out.m:
> > > Output any `pragma c_code' first for the LLDS backend. This is
> > > because variables may be defined in a `pragma c_code' and we want
> > > the definition to appear before any use of the variable. Also
> > > output the `pragma c_code' fragments in the same order they appear
> > > in the source file, as this is the more intuitive behaviour.
> >
> > I don't think this is the right approach to take. In fact, I think this
> > is broken.
>
> I agree.
>
> > If you want to declare variables in the c_code that can be referenced
> > from any place in the module, use pragma c_header_code, and put an
> > extern declaration in for the variable. Declarations should go in the
> > c_header code, definitions in c_code. (Perhaps the documentation should
> > be clearer on this issue?).
> >
> > Then it doesn't matter *where* you put the actual definition of the
> > variable.
> >
> > That way you can use --split-c-files and even if every procedure is put
> > in a separate file, they can all see the c_header_code, and know there
> > will be a variable defined somewhere to link to.
> >
> > Your change will just hide this problem -- the code will work fine when
> > in a single file but cannot be split into separate files without
> > breaking.
>
> Right. Note that the causes problems for `--intermodule-optimization'
> as well as for `--split-c-files', so it is something that we should
> not ignore.
>
In that case we should document that pragma c_code is not allowed to
contain a static global variable.
--------------------------------------------------------------------------
mercury-developers mailing list
Post messages to: mercury-developers at cs.mu.oz.au
Administrative Queries: owner-mercury-developers at cs.mu.oz.au
Subscriptions: mercury-developers-request at cs.mu.oz.au
--------------------------------------------------------------------------
More information about the developers
mailing list