octave-maintainers
[Top][All Lists]
Advanced

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

F77_CSTRING problem


From: Alexander Barth
Subject: F77_CSTRING problem
Date: Fri, 12 Jan 2007 16:49:39 -0500
User-agent: Thunderbird 1.5.0.7 (X11/20060913)

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'

This is expanded as:

std::vector< char > copy_vector (slen + 1); char *copy = ((slen + 1) > 0 ? 
&(copy_vector[0]) : 0);
memcpy (copy, s, slen); copy[slen] = '\0';

I can submit a patch, if someone (with more insight than me) thinks that my 
modified macro is right.


Thanks
Alex





reply via email to

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