(j3.2006) Get_Command_Argument

Bill Long longb
Thu Dec 15 17:04:29 EST 2011



On 12/15/11 3:41 PM, Van Snyder wrote:
>
> On Thu, 2011-12-15 at 13:07 -0800, Craig Dedo wrote:
>>          Comments, anyone?
>
> The discussion of UTF-16 and ISO-10646 is largely irrelevant to the
> original problem I had:
>
> I have a character string that needs to be sent to a C function.
>
> I get it from the command line, using Get_Command_Argument.
>
> Since I need to send it to a C function, it has to be kind C_Char.  This
> leads to two choices:
>
> 1.  Cross my fingers and hope C_Char is the same as default kind.  Yes,
> Bill is right that this is almost always the case.  In my line of work,
> I have become accustomed to "almost" eventually biting you in the
> backside, sometimes at enormous expense.  It's probably not a problem of
> such magnitude for command-line arguments, but hard-won habits die hard.
>
> 2.  Copy the string from the command line to the one that gets sent to
> the C function.
>

You would need to do this only in the case that the kinds were 
different, as in

  if (c_char /= KIND("A")) then
    ! copy get_command_argument string to C_string
    ! call Cfun(c_string)
else
    ! call Cfun(string//C_NULL_CHAR)
end if

Note that you end up making a tmp copy either way, so you might consider 
a general C function mkcstring (fstring, cstring, kind)  where kind is 
the KIND of the input Fortran string fstring, and the output C string 
cstring has the appended NULL character as well as being translated in 
the case that the kind argument value is not c_char.  Then the above 
reduces to

   call mkcstring(string, c_string, KIND("A"))
   call Cfun(c_string)


A bit clunky, but one assumes that calls to these functions would be 
very infrequent in a normal program.

Cheers,
bill



> Which leads back to the largely-ignored original question:
>
> Would it be unreasonable to allow C_Kind for the character arguments of
> Get_Command_Argument and Get_Environment_Variable?
>
>
> _______________________________________________
> J3 mailing list
> J3 at j3-fortran.org
> http://j3-fortran.org/mailman/listinfo/j3

-- 
Bill Long                                           longb at cray.com
Fortran Technical Support    &                 voice: 651-605-9024
Bioinformatics Software Development            fax:   651-605-9142
Cray Inc./Cray Plaza, Suite 210/380 Jackson St./St. Paul, MN 55101





More information about the J3 mailing list