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

Re: using tail in a pipe and script



On Sun, 30 Dec 2001 00:14:30 +0100, martin f krafft <madduck@madduck.net> wrote:

> also sprach Eric G. Miller <egm2@jps.net> [2001.12.29.2350 +0100]:
> > C always uses pass by value, C++ can do both.  But, what does that
> > have to do with shell scripts and pipes?
> 
> C can pass by reference, no?

No.  C always passes by value.  Passing a pointer always passes a copy of
the value.  That's why you must do things like pass pointers to pointers,
if a procedure will change the thing being pointed at.  For instance,

    double strtod (const char *nptr, char **endptr); 

then...
 {
    double dbl;
    char *ss, *buff = "42.2 Forty-Two and Two-Tenths";
    dbl = strtod (buff, &ss);
    if (ss == buff) { /* failed conversion */ }
    else { /* it worked */ }
  }

If "endptr" weren't a pointer to a pointer, it wouldn't be possible to
set *endptr to the location in the character string after the number (if
any).

> think about it: i pass by value when i pipe into a program, and i pass
> by reference when i tell that same program which file to read. standard
> unix filter procedure.
> 
> when passed as a pipe, the original data can't be modified.
> when passed as a file name, the data can be modified *and* there is
> nothing copied (ignoring what the program does)...

Somewhat analogous, but a pipe is a stream of bytes that is not exactly
analogous to passing by value, because if the program needs to move
around in that byte stream, it still must copy the data...

-- 
Eric G. Miller <egm2@jps.net>



Reply to: