octave-maintainers
[Top][All Lists]
Advanced

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

F77_CSTRING problem


From: John W. Eaton
Subject: F77_CSTRING problem
Date: Wed, 24 Jan 2007 13:30:48 -0500

On 12-Jan-2007, Alexander Barth wrote:

| Hi all,
| 
| I have a problem with the F77_CSTRING macro from f77-fnc.h. It should create 
a c-string from a
| Fortran string. Currently (CVS 12 Jan.), it is defined as:
| 
| #define F77_CSTRING(s, len, cs) \
|  OCTAVE_LOCAL_BUFFER (char, F77_CHAR_ARG_USE (s), \
|                     F77_CHAR_ARG_LEN_USE (s, len) + 1); \
|  memcpy (cs, F77_CHAR_ARG_USE (s), F77_CHAR_ARG_LEN_USE (s, len)); \
|  cs[F77_CHAR_ARG_LEN_USE(s, len)] = '\0'
| 
| A statement like:
| 
| F77_CSTRING(s,slen,copy);
| 
| is expanded as:
| 
|  std::vector< char > s _vector (slen + 1); char *s = ((slen + 1) > 0 ? &(s 
_vector[0]) : 0); memcpy
| (copy, s, slen); copy[slen] = '\0';
| 
| The first problem is the whitespace between "s" and "_vector". The second 
problem is that it should
| be "char *copy = ...." and not "char *s = ....", or am I wrong?
| 
| I redefined locally this macro as:
| 
| #define F77_CSTRING(s, len, cs) \
|  OCTAVE_LOCAL_BUFFER (char,cs, \
|                     F77_CHAR_ARG_LEN_USE (s, len) + 1); \
|  memcpy (cs, F77_CHAR_ARG_USE (s), F77_CHAR_ARG_LEN_USE (s, len)); \
|  cs[F77_CHAR_ARG_LEN_USE(s, len)] = '\0'

Yes, this looks correct now.  This macro is supposed to create a local
buffer of type std::vector<char> with the name CS_vector containing a
copy of the string S, along with a pointer named CS that references
the data in the CS_vector object.

I made this change.

Thanks,

jwe


reply via email to

[Prev in Thread] Current Thread [Next in Thread]