Mail Archives: djgpp/1999/03/08/21:04:49.1
Jeramie Hicks wrote:
>
> In my day (many moons ago), you either had a variable, or a ptr to a
> variable. If you needed the address of the variable, you used an & to
> get it... but that always occured either in function calls (for
> functions that wanted a ptr to a variable as an argument) or on the
> right side of an equal sign.
>
> I've been having coworkers ask me questions about C programming
> lately, and I've been kind of suprised at what their professors are
> teaching to them. For instance, I saw several times things like:
>
> char& a; // or
> &b = 5; // etc...
>
> being taught to do simple routine operations. Since I've NEVER used an
> amperstand on the left side of the equal sign, what's going on here?
> What do these statement do? What's the advantage to doing something
> like this? It just seems more confusing then when I learned it, and
> they're still doing the same old simple operations, just in a wierd
> way.
Looks like C++ to me, or else some weird compiler extension. I can't
speak to C++ myself, but in vanilla C AFAIK an `&' expression is never
an lvalue, so that shouldn't be valid.
The declaration looks wrong for C, but for C++ it's a reference
variable. Kind of like pass-by-pointer in plain C, except the compiler
does the indirection for you.
--
Nate Eldredge
nate AT cartsys DOT com
- Raw text -