I have submitted a new Ada example file, xt12a.adb and have made  
changes to x12a.adb according to the discussion several days ago  
about problems with emulating sprintf. I also made changes in  
x12a.adb so that it uses data structures from the thick binding  
rather than the thin binding. (See related note in another e-mail  
from me today.)

I think that it is generally not a good idea to make the Ada examples  
emulate C when there is an Ada way to get the job done. Those who are  
interested will see that rather than use sprintf and make Ada  
programmers (including this one 8^) scratch their heads, I used the  
'Image function. Generally, if there is a type T and X is a value of  
T, there is a function T'Image(X) which returns a string  
representation of the name of X unless T is an Integer type in which  
case the returned string consists of the digits of X along with a  
leading minus sign if X is negative.

Inversely, if S is a string containing a valid integer literal and T  
is an Integer type, then T'Value(S) is the numeric value of that  
literal. This is not used in this example, just FYI.

String (and 1D array) concatenation is accomplished using the &  
operator but that is not necessary in this example either.

Jerry


On May 24, 2007, at 4:48 PM, Alan W. Irwin wrote:

> On 2007-05-24 15:25-0600 Orion Poplawski wrote:
>
>> In plplot-5.7.3/examples/ada/x12a.adb, the sprintf function is  
>> declared
>> and imported as follows:
>>
>>     procedure Sprintf( buffer : out char_array; format : in  
>> char_array;
>> variable: in PLFLT );
>>     pragma Import(C, Sprintf, "sprintf" );
>>
>> This is incorrect because sprintf's declaration is sprintf (char *,
>> const char *, ...) (varargs) not sprintf (char *, const char *,  
>> float).
>>  This happens to work on i386 because of the ABI happens to be the
>> same.  It isn't on x86_64 and so crashes.  See
>> https://bugzilla.redhat.com/bugzilla/process_bug.cgi#c1 and the
>> http://gcc.gnu.org/onlinedocs/gnat_ugn_unw/Calling- 
>> Conventions.html note
>> about varargs for more info.
>>
>> If you really need to use sprintf you'll need to write a write a
>> sprintff(char *, const char *, float) wrapper to sprintf and  
>> interface
>> to that.  Likewise for any other arguments used (currently just  
>> the one).
>>
>> Not sure if any plplot routines use varargs arguments, but if so the
>> current ada imports are probably incorrect.
>
> Thanks, Orion, for your report.
>
> To answer Orion's last comment first, I looked in src/*.c for "..."  
> and there
> doesn't seem to be any libplplot routines with a variable number of
> arguments so I don't think that is going to be an issue.
>
> To answer Orion's second-last comment, I think we should look for  
> an Ada
> alternative to Importing the C sprintf function because of the  
> difficulties
> you have found with that method.  Virtually every language has a  
> native way
> to transform from integer, floating-point etc. representations, to  
> strings.
>
> Jerry, are you aware of the normal way to do this in Ada?  N.B.  
> this has
> nothing to do with API questions or our Ada interface and is merely a
> question about how to transform from integer and floating point
> representations to strings in Ada since that capability is needed for
> the Ada implemention of example 12 and several other of our examples.
>
> Alan


-------------------------------------------------------------------------
This SF.net email is sponsored by DB2 Express
Download DB2 Express C - the FREE version of DB2 express and take
control of your XML. No limits. Just data. Click to get it now.
http://sourceforge.net/powerbar/db2/
_______________________________________________
Plplot-devel mailing list
Plplot-devel@lists.sourceforge.net
https://lists.sourceforge.net/lists/listinfo/plplot-devel

Reply via email to