> Michael Rigby-Jones wrote: >>>> To pass by reference you pass a pointer, how is this feature >>>> missing? Olin replied: > I thought it was clear, in that having to pass a pointer manually is > exactly > what you are trying to avoid. Wouldn't it be nice if the compiler took > care > of this for you so that you don't have to remember to pass a pointer in > the > call and dereference in the routine? Real languages allow you to specify > pass by reference or pass by value with the compiler keeping track of the > details instead of you. It's interesting that the first language > (Fortran) > was originally pass by reference only. And I opine: One could make an argument that a calling sequence that doesn't distinguish call-by-value from call-by-reference at the point of the call is dangerous. You can't tell by looking at the call whether the args can be trashed by the callee. This is one case (of few) where IMHO C has an advantage over Pascal. In "C" arguments that can be trashed start with a "&" (except for arrays and that is indeed a problem). In Pascal you can't tell by looking at the call whether the args are pass-by-value or pass-by-reference. Note that C++'s reference types allow you to get the Pascal type behavior if that is what you really want. I tend to use them liberally, so I guess I like the Pascal way even in C++ :-) PS: I remember confusing people in Fortran by doing something like this: SUBROUTINE XX( ARG ) INTEGER ARG ARG = 2 RETURN END SUBROUTINE YY XX(1) I = 1 I ends up with the value 2 (and many other places 1 is referred to end up equal to 2!! Terrible and deadly! I believe most (all?) Pascal implementations complain loudly if you pass a constant value as a call-by-reference argument, and C won't let you take the address of a literal value (except of course for strings, which are really arrays and can cause no end of trouble, but const helps, and yes all the rules are confusing and yes that makes C hard to use). Finally, and completely unrelated to argument passing, here is my favorite crazy "C" ism (comments and indentation deliberately omitted to make it more confusing :-) // assume the following function exists to return non-zero if n is a prime number int checkPrime( int n ); // then this is a more efficient way to check for primes if you often call it with small integers int isPrime( int n ) { switch ( n ) default: if checkPrime(n) case 2: case 3: case 5: case 7: case 11: case 13: return 1; else case 4: case 6: case 8: case 9: case 10: case 12: return 0; } Yuck! -- Bob Ammerman RAm Systems -- http://www.piclist.com PIC/SX FAQ & list archive View/change your membership options at http://mailman.mit.edu/mailman/listinfo/piclist