Steve Thompson <> writes:
[...]
> No annoyance taken, although now that I think of it it does show an
> instance of overloaded semantics, which can be confusing. When I was
> less experienced with C, I was confused by the fact that variables
> defined as structures were not pointers:
>
> struct point {
> int x, y, z;
> };
>
> struct point a;
>
>
> One cannot reference 'a' (as such) in an expression even though it is
> a pointer in the implementation because C allows one to use structures
> as arguments to a function. I'd never do that in my own code, but
> some people may like the fact that they can pass complex data
> structures around as if they were simple variables. I think it wastes
> resources, but of course that is less of an issue today than it was
> when C was first developed.
I'm not sure what you mean when you say `a` "is a pointer in
the implementation", especially after you mention "the fact that
variables defined as structures were not pointers".
Whatever you meant, the fact it that `a` *isn't* a pointer; it's
the name of an object of type `struct point`, and the name `a`
certainly can be used in an expression: as the LHS or RHS of an
assignment, as a function argument, as an argument to `sizeof` or
`&`, as the left operand of `.`, and probably in other ways that
I haven't thought of. Of course `&a` is a pointer (not a pointer
object, but an expression of pointer type).
> These days I'm thinking more and more about cache-line usage, so I am
> concerned with preserving the 'hotness' of my data. Copying
> structures around a whole lot is hostile to this paradigm, so that is
> one language feature I am happy to avoid.
If a structure is smaller than a pointer, or not much bigger, it makes
perfect sense to pass it around by value.
--
Keith Thompson (The_Other_Keith)
kst- <http://www.ghoti.net/~kst>
Will write code for food.
"We must do something. This is something. Therefore, we must do this."
-- Antony Jay and Jonathan Lynn, "Yes Minister"