[M3devel] Constant to Constant?

Jay K jay.krell at cornell.edu
Fri Mar 12 02:06:57 CET 2010


Chris, I'm not sure I understand.

 

 

Is the result "in misc", or is it constant relative to the program's lifetime?

Or is it initialized on-demand and then constant from then on?

 

 

There are a few instances where "constants" are initialized in Modula-3 module initializers.

They are "VAR" from a technical point of view, in the .i3 file, but then VAR is immediately preceded by a comment that they are CONST.

  I do something similar in m3core/unix, except the data is actually const/static initialized in C code. I do that to avoid duplicating header content. Header content can be duplicated, if it is fairly portable and stable, only needs to be duplicated once, easy to get correct, and stay correct. The particular problem in m3core/unix is portability -- the header content would have to be duplicated differently for every target. Incorrectly duplicated C headers silently violate safety (see below).

 

 

You should try to provide a SAFE interface, so that client code can be SAFE.

And then, you are responsible for upholding what that means.

  Your module implementation might be UNSAFE.

  But clients must be protected from a "certain class of bug".

  For example, a claimed-to-be SAFE interface cannot expose stdlib/free() because a client could double free.

  This is an easy thing to mess up and it is very unfortunate when it is.

   It is roughly equivalent to bugs in the compiler or garbage collector.

 

 

 - Jay
 
> From: Highjinks at gmx.com
> To: m3devel at elegosoft.com
> Date: Fri, 12 Mar 2010 01:35:25 +0100
> Subject: [M3devel] Constant to Constant?
> 
> 
> Things are progressing here, slowly but steadily.
> 
> I'm curious...
> 
> When writing an interface for something like this ...
> 
> /* C Type */
> const C_Foo_t *Bar = get_foo_data(misc);
> 
> Is it better to do it this way...
> 
> <* EXTERNAL get_foo_data:C *>
> TYPE Foo_Data = PROCEDURE(get_foo_data(somemisc : misctype) : C_Foo_t;
> 
> Or should I just do...
> UNSAFE INTERFACE Foo;
> 
> (* Translating the C typedef struct over to Modula3 code. *)
> TYPE C_Foo_T = UNTRACED REF RECORD .... END;
> 
> <* EXTERNAL get_foo_data:C *>
> PROCEDURE get_foo_data(somemisc : misctype) : C_foo_t;
> END Foo.
> 
> Main.m3
> IMPORT Foo;
> Foo_Data := Foo.get_foo_data(Misc);
> END Main. 
> 
> C_Foo_t is known, and has a Modula 3 representation in the Interface. But as the C Code shows, it has to be a constant value.
> 
> What's the best way to do this without hosing the Interface for everyone else that might want to use it? Variable expressions are no problem, it's making it a constant that's giving me trouble. It's constant because the data structure is managed by the supporting library, not by the Modula3 Code.
> 
> Tips...pointers?
> 
> -- 
> Chris <Highjinks at gmx.com>
 		 	   		  
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://m3lists.elegosoft.com/pipermail/m3devel/attachments/20100312/e454964b/attachment-0002.html>


More information about the M3devel mailing list