Finding Available Length Of Strings...

Doug Gwyn gwyn at smoke.brl.mil
Sat Nov 10 16:25:26 AEST 1990


In article <16752 at hydra.gatech.EDU> gt4512c at prism.gatech.EDU (BRADBERRY,JOHN L) writes:
>When passing strings to other functions, what is the BEST way to find
>the bytes remaining in the formal string parameter (to prevent over-
>writting the end while in the function)?? Does it involve using the
>current starting address of the string parameter and calculating
>(somehow) the DEFINED end??

What on earth do you mean?  You don't pass strings to C functions; the
best you can do is pass pointers to arrays containing chars.  There is
no way to determine in the called function where the end of the array
allocation might be, given merely a pointer into it.

Conventionally, C programming relies heavily on 0-terminated char arrays
to represent character strings, but the 0 terminator value does not
normally indicate anything about the valid extent of the array within
which it lies.  (For string LITERALS it does, but you can't count on
being able to write into a string literal.  Some systems put them into
read-only memory.)



More information about the Comp.lang.c mailing list