[m-rev.] for review: fix link errors in profiling grades

Fergus Henderson fjh at cs.mu.OZ.AU
Thu Aug 15 20:04:58 AEST 2002


On 15-Aug-2002, Zoltan Somogyi <zs at cs.mu.OZ.AU> wrote:
> +
> +            (
> +                echo
> +                echo "extern void MR_CALL"
> +                echo -n "${prefix}${name}_p_0("
> +                n=1
> +                for arg in ${inputs} ${outputs}
> +                do
> +                    if test $n -gt 1
> +                    then
> +                        echo -n ", void *arg${n}"
> +                    else
> +                        echo -n "void *arg${n}"
> +                    fi
> +                    n=`expr $n + 1`
>                  done
> +                echo ");"

> +                echo "void MR_CALL"
> +                echo -n "${prefix}${name}_p_0("
> +                n=1
> +                for arg in ${inputs} ${outputs}
> +                do
> +                    if test $n -gt 1
> +                    then
> +                        echo -n ", void *arg${n}"
> +                    else
> +                        echo -n "void *arg${n}"
> +                    fi
> +                    n=`expr $n + 1`
> +                done
> +                echo ")"
> +                echo "{ MR_fatal_error(\"call to \" ${prefix}{name}_p_0); }"
> +            ) >> ${tmp_hlc}
> +        done
>      done
>  done

There should be a comment explaining why you emit the declarations
of these functions immediately before the defniitions.

I guess the reason is to suppress the usual GCC warning
about the function not having been declared before being
defined.  But in this case, the warning is not spurious.
The prototypes should go in the header file, rather than the C file,
and the header file should be included from library/profiling_builtin.m,
so that the C compiler will check that they are consistent with the
prototypes that the Mercury compiler generates for the Mercury
procedures declared `:- external' in profiling_builtin.m.

In fact, I think the prototypes that you've used here are not
the same as the prototypes that the compiler will generate.
Calling a function via a prototype which is different than
the one it was defined with violates the C standard, so this
is definitely problematic.  (I know of at least one C compiler
that exists today for which this violation of the standard would
cause trouble.  Not a popular one, but still...)

Now, if that is the intent, then at very least there should be
an XXX comment explaining that it doesn't conform with the C
standard and explaining why this is justified.

But it would be better to fix the problem.
One way to fix the problem would be to declare these functions
with the proper argument types (which are different depending
on whether or not --high-level-data is specified).
Another way would be to put profiling_builtin.m into its own
library that is only built and linked in for deep profiling grades.

-- 
Fergus Henderson <fjh at cs.mu.oz.au>  |  "I have always known that the pursuit
The University of Melbourne         |  of excellence is a lethal habit"
WWW: <http://www.cs.mu.oz.au/~fjh>  |     -- the last words of T. S. Garp.
--------------------------------------------------------------------------
mercury-reviews mailing list
post:  mercury-reviews at cs.mu.oz.au
administrative address: owner-mercury-reviews at cs.mu.oz.au
unsubscribe: Address: mercury-reviews-request at cs.mu.oz.au Message: unsubscribe
subscribe:   Address: mercury-reviews-request at cs.mu.oz.au Message: subscribe
--------------------------------------------------------------------------



More information about the reviews mailing list