http://gcc.gnu.org/bugzilla/show_bug.cgi?id=56149



--- Comment #5 from Steve Kargl <sgk at troutmask dot apl.washington.edu> 
2013-01-31 15:54:56 UTC ---

On Wed, Jan 30, 2013 at 07:58:27PM +0000, paul.laidler at ntlworld dot com

wrote:

> --- Comment #2 from Paul Laidler <paul.laidler at ntlworld dot com> 
> 2013-01-30 19:58:27 UTC ---

> 

> Many thanks for your reply and interest.

> 

> The ClearWin+ function winio@ (winio$ in gFortran) emulates the C function

> printf that takes a format string then a variable number of arguments

> depending on the content of the format. The function can be programmed in C

> on the basis that all arguments are passed as 64 bit addresses until you

> get to the length of the format string which has a size well below the

> minimum possible address value. Any arguments after that will also be

> string lengths. The format string cannot be processed to find out what

> arguments are supplied until we know its length.



My only interest here is to clearly define the issue.  With that

in mind, is winio a function written in C (or at least has a C

prototype) with the form "int winio(char *string, ...);"?



If the answer is "yes", then the issue is not related to gfortran's

implementation of the ISO C Binding feature.  The Fortran 2003 

standard specifically states that vardiac functions are not covered

under BIND(C): 



  NOTE 15.21

  The C language allows specification of a C function that can take a

  variable number of arguments (C standard, 7.15).  This standard does

  not provide a mechanism for Fortran procedures to interoperate with

  such C functions.



It seems to me that the only portable solution to your issue is to

tell your users that the proper way to call winio from Fortran is



   call winio("Some string" // C_NULL_CHAR, ...);

or

   call winio(trim(string) // C_NULL_CHAR, ...);



In your implementation of winio, you will now have a terminated 

string.  You can parse the string and not depend on the hidden

length.



As Tobias notes, changing the hidden length from a 32-bit integer

to a 64-bit integer breaks backwards compatibility.  The gfortran

developer would now need to tell everyone else that may be 

mucking around with the hidden length argument to change their

code.  Everyone with libraries and modules that use Fortran strings

would also likely need to recompile.

Reply via email to