Groups | Search | Server Info | Keyboard shortcuts | Login | Register [http] [https] [nntp] [nntps]


Groups > comp.lang.c > #27530

Re: Compatibility question

Path csiph.com!newsfeed.hal-mli.net!feeder3.hal-mli.net!newsfeed.hal-mli.net!feeder1.hal-mli.net!border3.nntp.dca.giganews.com!Xl.tags.giganews.com!border1.nntp.dca.giganews.com!nntp.giganews.com!local2.nntp.dca.giganews.com!nntp.supernews.com!news.supernews.com.POSTED!not-for-mail
NNTP-Posting-Date Mon, 22 Oct 2012 13:47:52 -0500
From Steve Thompson <stevet810@gmail.com>
Newsgroups comp.lang.c
Subject Re: Compatibility question
Date Mon, 22 Oct 2012 18:42:59 +0000
Organization Friends of the Galactic Collective
Message-ID <qRFu8I.lcH.7XEwQ@gmail.com> (permalink)
References <bTPtYj.bf9.VEBUJ@gmail.com> <aegfofFnpi3U14@mid.individual.net> <SodxpQ.GJL.0E2fB@gmail.com> <aejeq5FqjpsU11@mid.individual.net> <OYMHVs.wix.4bcJD@gmail.com> <0.a87a1c8a472d870b0466.20121022022701BST.87y5izxpne.fsf@bsb.me.uk> <JLOhFS.Dvd.FY9Iy@gmail.com> <0.d779297035d2edccd1b4.20121022173052BST.87ehkqbhab.fsf@bsb.me.uk> <2nYjPo.Krd.2aRbe@gmail.com> <lnfw56fl74.fsf@nuthaus.mib.org>
Mime-Version 1.0
Content-Type text/plain; charset=us-ascii
Content-Transfer-Encoding 7bit
User-Agent NN 6.4.3
Lines 71
X-Trace sv3-aT810ey6+bvik32pBC/xZsTVeL8Z413aGqNvHSavuyyFJ8m3G9G3ukv9Roh07vEnPMa9K9RCidH5kzN!uoNTgwl16fF2tLUWsZ046FRS9Hrg5hPkXJYA+IG6awChyd/yzhPdlpZg4PklEg==
X-Complaints-To www.supernews.com/docs/abuse.html
X-DMCA-Complaints-To www.supernews.com/docs/dmca.html
X-Abuse-and-DMCA-Info Please be sure to forward a copy of ALL headers
X-Abuse-and-DMCA-Info Otherwise we will be unable to process your complaint properly
X-Postfilter 1.3.40
X-Original-Bytes 4460
Xref csiph.com comp.lang.c:27530

Show key headers only | View raw


On Mon, Oct 22, 2012 at 10:52:47AM -0700, Keith Thompson wrote:
> Steve Thompson <stevet810@gmail.com> 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".

Meaning that under the hood in the C compiler, 'a' is really a
pointer.  The logic of the compiler causes it to use the structure
data as specified in the standard, but conceptually 'a' is still a
pointer to the data in the specific structure identified by 'a'.  I
found it very confusing when I was learning C.

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

True enough, but the difference is that a structure cannot be used for
arithmetic operations of any kind in C.  That makes it fundamentally
different from simple type variables.  It may be meaningful to say that
structures passed to functions as values is a hack in the C language.
It fills a use-case scenario that will be found (or should be found)
only in trivial programs, IMHO.
 
> > 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.

Most structures are considerably larger than a pointer in practice.
My personal opinion is that it is a waste to pass them around by
value in most cases.  Small structures are likely to be associated
with arrays of same, and all that copying will add up in non-trivial
applications.



Regards,

Steve Thompson

-- 
GOTO's are like guns.  Safety is entirely contingent on the user.

Back to comp.lang.c | Previous | Next — Previous in thread | Next in thread | Find similar | Unroll thread


Thread

Compatibility question Steve Thompson <stevet810@gmail.com> - 2012-10-20 03:08 +0000
  Re: Compatibility question Ian Collins <ian-news@hotmail.com> - 2012-10-20 16:20 +1300
    Re: Compatibility question Ben Bacarisse <ben.usenet@bsb.me.uk> - 2012-10-20 11:50 +0100
      Re: Compatibility question Keith Thompson <kst-u@mib.org> - 2012-10-20 11:41 -0700
        Re: Compatibility question Steve Thompson <stevet810@gmail.com> - 2012-10-21 23:04 +0000
          Re: Compatibility question Barry Schwarz <schwarzb@dqel.com> - 2012-10-21 20:27 -0700
    Re: Compatibility question Steve Thompson <stevet810@gmail.com> - 2012-10-20 04:01 +0000
      Re: Compatibility question Ian Collins <ian-news@hotmail.com> - 2012-10-21 09:26 +1300
        Re: Compatibility question Steve Thompson <stevet810@gmail.com> - 2012-10-21 22:54 +0000
          Re: Compatibility question Ian Collins <ian-news@hotmail.com> - 2012-10-22 12:29 +1300
            Re: Compatibility question Steve Thompson <stevet810@gmail.com> - 2012-10-21 23:50 +0000
              Re: Compatibility question Ben Bacarisse <ben.usenet@bsb.me.uk> - 2012-10-22 02:27 +0100
                Re: Compatibility question Steve Thompson <stevet810@gmail.com> - 2012-10-22 02:28 +0000
                Re: Compatibility question Eric Sosman <esosman@comcast-dot-net.invalid> - 2012-10-22 11:18 -0400
                Re: Compatibility question Steve Thompson <stevet810@gmail.com> - 2012-10-22 16:19 +0000
                Re: Compatibility question Ben Bacarisse <ben.usenet@bsb.me.uk> - 2012-10-22 17:37 +0100
                Re: Compatibility question Ben Bacarisse <ben.usenet@bsb.me.uk> - 2012-10-22 17:40 +0100
                Re: Compatibility question Ben Bacarisse <ben.usenet@bsb.me.uk> - 2012-10-22 17:30 +0100
                Re: Compatibility question Steve Thompson <stevet810@gmail.com> - 2012-10-22 17:23 +0000
                Re: Compatibility question Keith Thompson <kst-u@mib.org> - 2012-10-22 10:52 -0700
                Re: Compatibility question Steve Thompson <stevet810@gmail.com> - 2012-10-22 18:42 +0000
                Re: Compatibility question Ben Bacarisse <ben.usenet@bsb.me.uk> - 2012-10-22 21:06 +0100
                Re: Compatibility question Steve Thompson <stevet810@gmail.com> - 2012-10-22 22:52 +0000
                Re: Compatibility question Ben Bacarisse <ben.usenet@bsb.me.uk> - 2012-10-23 03:33 +0100
                Re: Compatibility question Steve Thompson <stevet810@gmail.com> - 2012-10-23 12:28 +0000
                Re: Compatibility question "BartC" <bc@freeuk.com> - 2012-10-23 16:45 +0100
                Re: Compatibility question Steve Thompson <stevet810@gmail.com> - 2012-10-23 17:53 +0000
                Re: Compatibility question Keith Thompson <kst-u@mib.org> - 2012-10-23 12:41 -0700
                Re: Compatibility question "BartC" <bc@freeuk.com> - 2012-10-23 21:28 +0100
                Re: Compatibility question Ben Bacarisse <ben.usenet@bsb.me.uk> - 2012-10-23 20:57 +0100
                Re: Compatibility question Keith Thompson <kst-u@mib.org> - 2012-10-23 12:26 -0700
                Re: Compatibility question Steve Thompson <stevet810@gmail.com> - 2012-10-23 20:39 +0000
                Re: Compatibility question Keith Thompson <kst-u@mib.org> - 2012-10-23 15:53 -0700
                Re: Compatibility question "BartC" <bc@freeuk.com> - 2012-10-24 00:57 +0100
                Re: Compatibility question Keith Thompson <kst-u@mib.org> - 2012-10-23 20:06 -0700
                Re: Compatibility question "BartC" <bc@freeuk.com> - 2012-10-24 11:18 +0100
                Re: Compatibility question Keith Thompson <kst-u@mib.org> - 2012-10-24 12:04 -0700
                Re: Compatibility question "BartC" <bc@freeuk.com> - 2012-10-24 23:10 +0100
                Re: Compatibility question Keith Thompson <kst-u@mib.org> - 2012-10-24 16:58 -0700
                Re: Compatibility question "BartC" <bc@freeuk.com> - 2012-10-25 01:46 +0100
                Re: Compatibility question Keith Thompson <kst-u@mib.org> - 2012-10-24 19:40 -0700
                Re: Compatibility question Steve Thompson <stevet810@gmail.com> - 2012-10-24 20:20 +0000
                Re: Compatibility question Keith Thompson <kst-u@mib.org> - 2012-10-24 14:38 -0700
                Re: Compatibility question James Kuyper <jameskuyper@verizon.net> - 2012-10-24 17:55 -0400
                Re: Compatibility question Keith Thompson <kst-u@mib.org> - 2012-10-24 16:29 -0700
                Re: Compatibility question Greg Martin <greg@softsprocket.com> - 2012-10-24 15:21 -0700
                Re: Compatibility question Steve Thompson <stevet810@gmail.com> - 2012-10-26 03:30 +0000
                Re: Compatibility question Ben Bacarisse <ben.usenet@bsb.me.uk> - 2012-10-26 13:02 +0100
                Re: Compatibility question Steve Thompson <stevet810@gmail.com> - 2012-10-27 00:04 +0000
                Re: Compatibility question Ben Bacarisse <ben.usenet@bsb.me.uk> - 2012-10-27 20:15 +0100
                Re: Compatibility question Joe Pfeiffer <pfeiffer@cs.nmsu.edu> - 2012-10-27 16:36 -0600
                Re: Compatibility question Steve Thompson <stevet810@gmail.com> - 2012-10-28 17:36 +0000
                Re: Compatibility question Phil Carmody <thefatphil_demunged@yahoo.co.uk> - 2012-10-27 22:42 +0300
                Re: Compatibility question Greg Martin <greg@softsprocket.com> - 2012-10-27 14:30 -0700
                Re: Compatibility question "BartC" <bc@freeuk.com> - 2012-10-27 22:57 +0100
                Re: Compatibility question Keith Thompson <kst-u@mib.org> - 2012-10-27 17:04 -0700
                Re: Compatibility question Keith Thompson <kst-u@mib.org> - 2012-10-27 17:14 -0700
                Re: Compatibility question Keith Thompson <kst-u@mib.org> - 2012-10-27 18:04 -0700
                Re: Compatibility question Keith Thompson <kst-u@mib.org> - 2012-10-24 16:46 -0700
                Re: Compatibility question Steve Thompson <stevet810@gmail.com> - 2012-10-25 01:18 +0000
                Re: Compatibility question Phil Carmody <thefatphil_demunged@yahoo.co.uk> - 2012-10-27 21:08 +0300
                Re: Compatibility question Steve Thompson <stevet810@gmail.com> - 2012-10-28 17:38 +0000
                Re: Compatibility question "BartC" <bc@freeuk.com> - 2012-10-23 00:38 +0100
                Re: Compatibility question Keith Thompson <kst-u@mib.org> - 2012-10-22 16:50 -0700
                Re: Compatibility question Steve Thompson <stevet810@gmail.com> - 2012-10-23 12:33 +0000
                Re: Compatibility question Öö Tiib <ootiib@hot.ee> - 2012-10-22 14:23 -0700
                Re: Compatibility question James Kuyper <jameskuyper@verizon.net> - 2012-10-22 17:26 -0400
                Re: Compatibility question Ian Collins <ian-news@hotmail.com> - 2012-10-23 10:55 +1300
                Re: Compatibility question Steve Thompson <stevet810@gmail.com> - 2012-10-22 23:27 +0000
                Re: Compatibility question "BartC" <bc@freeuk.com> - 2012-10-22 22:44 +0100
                Re: Compatibility question Les Cargill <lcargill99@comcast.com> - 2012-10-22 17:15 -0500
                Re: Compatibility question "BartC" <bc@freeuk.com> - 2012-10-23 00:13 +0100
                Re: Compatibility question James Kuyper <jameskuyper@verizon.net> - 2012-10-22 18:35 -0400
                Re: Compatibility question "BartC" <bc@freeuk.com> - 2012-10-23 00:14 +0100
                Re: Compatibility question Steve Thompson <stevet810@gmail.com> - 2012-10-22 23:42 +0000
                Re: Compatibility question Ian Collins <ian-news@hotmail.com> - 2012-10-23 13:35 +1300
                Re: Compatibility question Keith Thompson <kst-u@mib.org> - 2012-10-22 17:01 -0700
                Re: Compatibility question "BartC" <bc@freeuk.com> - 2012-10-23 01:47 +0100
              Re: Compatibility question Keith Thompson <kst-u@mib.org> - 2012-10-21 19:27 -0700

csiph-web