Re: ISO_C_BINDING and C strings conversion

On Jan 20, 11:06 am, nos...@xxxxxxxxxxxxx (Richard Maine) wrote:
Gary L. Scott <garylsc...@xxxxxxxxxxxxx> wrote:

I typically just delete the null(s) from the C string (replace with a
space character) procedure is called "deletenulls" (not really a
conversion so much as a kludging)

That description might be misleading me, but I'd normally expect to have
to replace not just the null(s), but everything after the first null.

If it is a "proper" C string, then there should be only one null, with
nothing after it, but your (s) makes me assume this isn't always the
case for what you are talking about.

If it is a C string stored in some fixed-size Fortran string or array,
then there might well be garbage after the first null. You then need to
replace all that garbage with blanks - not just the pieces that happen
to be null. Otherwise, you get garbage in your result. Been there; done
that; have also fixed that bug in other people's code.

Richard Maine                    | Good judgment comes from experience;
email: last name at domain . net | experience comes from bad judgment.
domain: summertriangle           |  -- Mark Twain

Of course. I typically initialize to blanks before using a string.
I've never had a properly functioning C procedure overwrite anything
beyond the null character in my always long-enough buffer, but I
suppose its possible.

Relevant Pages

  • Re: inconsistent behavior of >FLOAT
    ... Accepting a string of blanks as 0 is a requirement in Forth-94. ... While>FLOAT is not required to treat a string of blanks as zero, ...
  • Re: Killing dead spaces around pipe delimiter
    ... ' DBFILE ... while and eventually test it to convince myself that the 2nd gsub() ... blanks is because that first gsubwill return 1 even if there are no ... I imagine the implementation probably has 2 steps - 1) find a string in the ...
  • Re: Performance RPG Figurative Constants versus Literals
    ... in compilation times between the two methods, ... I would suspect that the compiler would store *blanks as a single byte ... I would also suspect that comparing ... a 132 character string to a figurative constant would be quicker in the ...
  • Re: inconsistent behavior of >FLOAT
    ... numeric data field filled with all blanks is interpreted as number 0. ... then an empty string will automatically resolve to the number 0. ... Numeric conversion functions in other languages behave similarly ... with respect to empty strings, ...
  • Re: Removing a character from a string
    ... OK I may well add a "remove_ch" string function to my existing string ... If s contains trailing blanks, or if s contains one or more ... In the case where the character is to be removed, ... the PACK effectively moves them to the right-hand end of the string. ...