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

Re: using tail in a pipe and script



On Sun, Dec 30, 2001 at 12:14:30AM +0100, martin f krafft 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, but it can fake it good enough.  Pointers are passed by value, but
the thing they point to is (obviously) not.  Thus the effect of
pass-by-reference is achieved, iff you do not try to assign a new
value to the pointer.  Eg :

/*
 * copy a string without the potential for a buffer overflow,
 * len is the capacity of 'dest'
 */
void my_strcpy( char* source , char* dest , int len )
{
    int src_len = strlen( source ) ;
    if ( src_len > len )
        dest = realloc( dest , (src_len+1)*sizeof( char ) ) ;
    ...
}
    
:-)

| 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)...

I see now.  I didn't get the analogy at first.

-D

-- 

Failure is not an option.  It is bundled with the software.



Reply to: