[m-dev.] for review: cleanup of type_ctor_infos, relative diff 1

Fergus Henderson fjh at cs.mu.OZ.AU
Thu Mar 9 16:54:36 AEDT 2000


On 09-Mar-2000, Zoltan Somogyi <zs at cs.mu.OZ.AU> wrote:
> On 08-Mar-2000, Fergus Henderson <fjh at cs.mu.OZ.AU> wrote:
> > > +:- type module_sub_info --->
> > > +	module_sub(
> > 
> > That change does not match the layout conventions documented
> > in the "Layout" section of our Mercury coding standard.
> 
> No, but it does avoid several 
> 
> > > diff -rub --exclude CVS ws15.base/runtime/mercury_deep_copy_body.h /home/ender2/zs/ws15/runtime/mercury_deep_copy_body.h
> > ...
> > > @@ -513,9 +556,14 @@
> > >      case MR_TYPECTOR_REP_STRING:
> > >          {
> > >              Word    *data_value;
> > > -            int     data_tag; 
> > > +			Word	data_tag;
> > > +
> > > +			/*
> > > +			** Not all Mercury strings are aligned; in particular,
> > > +			** string constants containing the empty string may be
> > > +			** allocated unaligned storage by the C compiler.
> > > +			*/
> > >  
> > > -            /* XXX simplify: tag should be zero */
> > >              data_tag = MR_tag(data);
> > >              data_value = (Word *) MR_body(data, data_tag);
> > 
> > Hmm, the code here doesn't make sense in light of the comment.
> > If the pointer is not aligned, won't stripping off the tag
> > give the wrong result?
> 
> The following code was not using either data_tag or data_value, except
> to test whether data_value was in range; I therefore deleted them and
> modified the test to test the variable data directly instead.
> 
> > It's still not clear to me why the layout_init alternative is needed.
> 
> Because unions in C do not allow you to say which member you are initializing,
> and force you to initialize the first member.

That comment makes it much clearer.  I think it would be helpful
to include a comment like that in the source code.  Inserting
"static initializers for " in front of "unions" would also make it clearer.  
And you should change "C" to "ANSI/ISO C (89)", since both GNU C and C99
provide ways to say which member you are initializing.

in GNU C, you can use a cast to a union type

	const union foo x = (union foo) whatever;

The compiler will pick the union element whose type matches,
or report an error if there is no such element.

in C99 you can use "designated initializers" to pick a specific
member to initialize.

	const union foo x = { [member_name] = whatever };

-- 
Fergus Henderson <fjh at cs.mu.oz.au>  |  "I have always known that the pursuit
WWW: <http://www.cs.mu.oz.au/~fjh>  |  of excellence is a lethal habit"
PGP: finger fjh at 128.250.37.3        |     -- the last words of T. S. Garp.
--------------------------------------------------------------------------
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