CVS difference for ais/ai-00131.txt

Differences between 1.4 and version 1.5
Log of other versions for file ais/ai-00131.txt

--- ais/ai-00131.txt	1998/11/05 18:19:10	1.4
+++ ais/ai-00131.txt	1998/11/18 19:41:48	1.5
@@ -1743,3 +1743,207 @@
 
 ****************************************************************
 
+From: 	Pascal Leroy[SMTP:phl@RATIONAL.COM]
+Sent: 	Friday, November 06, 1998 5:26 AM
+Subject: 	Re: AI-00131: function results
+
+I am looking at AI-00131 again, and I am puzzled by the following issue:
+
+In ANSI C, a function can return a struct (of course, it can also return a
+pointer to a struct).  The RM (i.e., the implementation advice in B.3(63-71))
+doesn't offer any guidance regarding the correspondance between the return
+type of a C function and the return type of the corresponding Ada function.
+
+The situation is quite clear in the case of scalars, but in the case of
+structs, it seems that the RM as it stands doesn't make it possible to write a
+portable interface (since it specifies nothing, the behavior is presumably
+implementation-defined).  Should C_Pass_By_Copy also apply to function
+results? Or am I missing something?
+
+Pascal
+
+****************************************************************
+
+From: 	Robert Dewar[SMTP:dewar@GNAT.COM]
+Sent: 	Friday, November 06, 1998 6:52 AM
+Subject: 	Re: AI-00131: function results
+
+I think it is quite wrong for an Ada function that specifies a record to
+be returned to accept a pointer-to-record, that seems strange. It would
+mean that an implicit dereference had to occur, which just seems wrong
+to me. This is quite different from the IN parameter case, where the
+corespondence is between call-by-reference on the Ada side, and passing
+pointers byt value on the C side.
+
+There is no return-by-reference (at least not in the sense that would be
+relevant here).
+
+So I think it is clear that this is NOT controlled by the pragma, if you
+specify that a function returns a record on the Ada side, then it must
+return a struct on the C side.
+
+****************************************************************
+
+From: 	Pascal Leroy[SMTP:phl@RATIONAL.COM]
+Sent: 	Friday, November 06, 1998 9:15 AM
+Subject: 	Re: AI-00131: function results
+
+> if you
+> specify that a function returns a record on the Ada side, then it must
+> return a struct on the C side.
+
+That's a very reasonable statement, but I still find worrisome that the RM
+doesn't say a word on this topic.
+
+Pascal
+
+****************************************************************
+
+From: 	Tucker Taft[SMTP:stt@INMET.COM]
+Sent: 	Friday, November 06, 1998 10:40 AM
+Subject: 	Re: AI-00131: function results
+
+I think there is the usual confusion between what the C source code
+looks like, and what the generated machine code looks like.
+When a struct is returned at the source level, at the generated
+machine code level, C often does the same thing that Ada does,
+have the caller pass in a pointer to a place on the stack where
+the result should be placed.
+
+If the object is sufficiently small, then rather than using a
+caller-allocated stack temp for the function result, one or more
+registers are used.  The question is whether one purpose of this
+pragma (or perhaps some alternative one we invent) is to distinguish
+between these two approaches at the machine code level, or
+whether we presume that the Ada compiler should "know" enough about
+the C compiler(s) on the target to make the right choice without
+direction.
+
+This is analogous to the parameter passing case, though in that
+case there are three alternatives at the machine code level for
+something which at the C source code level is by-value (rather
+than by pointer): pass in registers if sufficiently short, push onto
+the stack if medium size, and pass a pointer to a temp if very large.
+
+I think the C_Pass_By_Copy pragma has always suffered from
+a confusion between the source issues and the machine-level issues.
+It partly stems from the fact that some Ada compilers "know" more
+about how the target C compiler works, or there is a standard
+ABI, while other Ada compilers know less about the target C compiler
+and are using pragmas (like this one) to figure out what to do.
+
+Hopefully this AI would clarify the situation somewhat.
+
+-Tuck
+
+****************************************************************
+
+From: 	Robert Dewar[SMTP:dewar@GNAT.COM]
+Sent: 	Friday, November 06, 1998 8:33 AM
+Subject: 	Re: AI-00131: function results
+
+<<That's a very reasonable statement, but I still find worrisome that the RM
+doesn't say a word on this topic.
+
+Pascal
+>>
+
+Doesn't worry me, the RM is totally broken in this area anyway. Better it
+say nothing than make a horrible mistake saying the wrong thing, as was the
+case with records passed as parameters.
+
+As long as implementations do the right thing, who cares what the RM says
+in implementation advice? What is troublesome is when the RM has wrong
+advice :-)
+
+Certainly the AI can most certainly clean this up, but this AI is not a
+terribly important one anyway, since it only affects impl advice.
+
+The critical issue here wrt Pass_By_Copy has not been what the RM says,
+because that can be ignored, since it is impl advice, but rather trying
+to make compilers do the same thing.
+
+I personally think C_Pass_By_Copy is a horrible kludge. Nothing the RM
+says will change my mind. The reason we implemented it was to be compatible
+with what the IM front end did. I am not sure we made the right choice in
+doing this, but for sure what the RM said was not a factor in our
+thinking at all!
+
+The AI is about matching the RM to practice, not influencing practice!
+
+****************************************************************
+
+From: 	Robert Dewar[SMTP:dewar@GNAT.COM]
+Sent: 	Friday, November 06, 1998 11:02 AM
+Subject: 	Re: AI-00131: function results
+
+<<If the object is sufficiently small, then rather than using a
+caller-allocated stack temp for the function result, one or more
+registers are used.  The question is whether one purpose of this
+pragma (or perhaps some alternative one we invent) is to distinguish
+between these two approaches at the machine code level, or
+whether we presume that the Ada compiler should "know" enough about
+the C compiler(s) on the target to make the right choice without
+direction.
+>>
+
+Of course the compiler has to know how to pass parameters. It is
+definitely NOT the function of the C_Pass_By_COpy pragma to tell
+the compiler whether to pass in registers or not.
+
+The C_Pass_By_Copy pragma merely means that you pass it the way
+C would pass a struct, no more, no less, so I don't really see
+any confusion at all here.
+
+It is the same as for an Integer passed to a C int. the compiler has
+to know whether to put this in a register, on the stack or ???
+
+The only reason we have an issue is the injudicious advice in the RM
+to do what is in fact clearly the wrong thing!
+
+In the case of returned values, we have no bad advice to tackle, so there
+is no issue. I think the AI will just confuse things if it starts talking
+about the implementation level issues that Tuck raises.
+
+The deal is simple, if you write
+
+   function q returns x;
+   pragma Import (q);
+
+where x is a record type, then this must use a calling sequence compatible
+with the C function
+
+   cx q();
+
+where cx is the corresponding C struct.
+
+No discussion of registers, stacks, or any other low level stuff is
+needed. It is always the job of the Ada compiler to know how to pass
+stuff according to the specified convention. A compiler that does not
+know enough should NOT attempt to recognize the convention!
+
+****************************************************************
+
+From: 	Robert A Duff[SMTP:bobduff@WORLD.STD.COM]
+Sent: 	Monday, November 09, 1998 3:28 PM
+Subject: 	Re: AI-00131: function results
+
+> Of course the compiler has to know how to pass parameters. It is
+> definitely NOT the function of the C_Pass_By_COpy pragma to tell
+> the compiler whether to pass in registers or not.
+
+I agree with Robert.  The RM, and the AI, only need to talk about what
+Ada decls correspond to what C decls.  There's no need to mention
+anything about registers, and temporary copies that are then passed by
+ref, &c -- for all that stuff, the Ada compiler just has to get it
+right.  Yes, that generally means the Ada compiler writer has to know
+what the C compiler is going to do.
+
+I also agree with Robert that the original RM rule that made
+C_Pass_By_Copy_Necessary, was mistaken -- and I take part of the blame
+for that.
+
+- Bob
+
+****************************************************************
+

Questions? Ask the ACAA Technical Agent