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


Groups > comp.lang.c > #4645

Re: Types in C

From Uncle Steve <stevet810@gmail.com>
Newsgroups comp.lang.c
Subject Re: Types in C
Date 2011-05-23 21:27 -0400
Organization Friends of the Galactic Collective
Message-ID <e086f8c7d12fb8d-c2f4b@gmail.com> (permalink)
References (5 earlier) <9401m9Ft2pU9@mid.individual.net> <50d915539d62563-19304@gmail.com> <9405q4Ft2pU12@mid.individual.net> <56d1adcc041e87f-81300@gmail.com> <940aukFt2pU18@mid.individual.net>

Show all headers | View raw


On Tue, May 24, 2011 at 12:03:32PM +1200, Ian Collins wrote:
> On 05/24/11 11:33 AM, Uncle Steve wrote:
> >On Tue, May 24, 2011 at 10:35:48AM +1200, Ian Collins wrote:
> >>On 05/24/11 09:53 AM, Uncle Steve wrote:
> >>>On Tue, May 24, 2011 at 09:25:29AM +1200, Ian Collins wrote:
> >>>>On 05/24/11 08:51 AM, Uncle Steve wrote:
> >>>>>On Mon, May 23, 2011 at 07:45:24PM +0000, Seebs wrote:
> >>>>>>On 2011-05-23, Keith Thompson<kst-u@mib.org>    wrote:
> >>>>>>>Just a quibble: size_t may be exactly the same type as unsigned long,
> >>>>>>>since a typedef merely creates an alias for an existing type, not
> >>>>>>>a new and distinct type.  plain char and signed char (for example)
> >>>>>>>are distinct in a way that size_t and unsigned long (for example)
> >>>>>>>are not.
> >>>>>>
> >>>>>>True.  Although, possibly confusingly, there are places where it seems
> >>>>>>that the thing a typedef creates is itself then called "a type".  The
> >>>>>>wording is a bit fuzzy.
> >>>>>>
> >>>>>>We all know what we mean, I think.  You could say it several ways:
> >>>>>>
> >>>>>>	Typedef does not actually create types; instead, it creates
> >>>>>>	names which refer to existing types.
> >>>>>>
> >>>>>>	Typedef creates types, but those types are identical to existing
> >>>>>>	types and can be used interchangably with them.
> >>>>>
> >>>>>How about the idea that typedefs create aliases for the basic built-in
> >>>>>types supplied by the language spec.?
> >>>>
> >>>>A typedef may provide an alias to any existing type, built-in, user
> >>>>defined or even incomplete.
> >>>
> >>>There are no "user defined" types in C.
> >>
> >>If they aren't defined buy programmers, who are they defined by?
> >
> >The compiler writers.  See my recent reply to Peter Seebach.
> 
> So if I write struct Point { int x,y; }; do I become a compiler writer?

Perhaps, but only in your Special Place...
 
> The distinction you attempt to draw in the other reply is an artificial 
> one that does not apply to C.

There's another one to look at as well, in which I attempt to clarify
the evident confusion over the terminology.
 
> >>>Structures and unions are
> >>>aggregates of basic types (and structures/unions).
> >>
> >>Well if you want to be pedantic, unions aren't aggregate types because
> >>they can only contain one member at a time.
> >>
> >>Let's expand the above for completeness:
> >>
> >>A typedef may provide an alias to any existing type, built-in,
> >>aggregate, union, composite or even incomplete.
> >>
> >>There, did I leave anything out?
> >
> >No, it seems very reasonable.
> 
> Good, that's a start.
> 
> >>>I believe
> >>>incomplete types are a (usually temporary) artifact of the compilation
> >>>process and you won't ever see them in a running program.
> >>
> >>Have you ever used void*?  What about a library with an opaque handle 
> >>type?
> >
> >void * is a non-specific pointer, with special semantics contrasted to
> >normal pointer types.  It is not "incomplete".
> 
> See 6.2.5 p19.
> 
> >Perhaps my internal
> >representation of "incomplete type" is wrong.  I labor under the
> >delusion that a structure defined with an element whose type is not
> >known is incomplete:
> >
> >struct incomplete {
> >    int        foo;
> >    struct bar something;
> >};
> 
> It is, the compiler interprets "struct bar something;" as a forward 
> declaration of struct bar.
> 
> >until the compiler encounters a definition of "struct bar", struct
> >incomplete is precisely that, and cannot be used to define anything.
> 
> Which is why we use a pointer member for incomplete types:
> 
> struct bar;
> 
> struct incomplete {
>      int        foo;
>      struct bar* something;
> };
> 
> >This produces an error if there is no struct bar definition because
> >the compiler cannot guess what code to generate.  Hence, it would
> >never be encountered at run-time.  Please correct me if this is not
> >the case.
> 
> It is, but a pointer to an incomplete may be used.

I see the logic, as pointers ought to be the same size regardless of
the thing they point to.  But of what use is it to define an
incomplete pointer type?  All you can do is suppress warnings by
casting any assignment to a complete type that the compiler knows
about.



Regards,

Uncle Steve

-- 
Should a professional politician be charged with molestation if he
kisses babies while attending political rallies?

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


Thread

Types in C jacob navia <jacob@spamsink.net> - 2011-05-22 21:29 +0200
  Re: Types in C Keith Thompson <kst-u@mib.org> - 2011-05-22 12:48 -0700
  Re: Types in C Ben Bacarisse <ben.usenet@bsb.me.uk> - 2011-05-22 23:03 +0100
    Re: Types in C jacob navia <jacob@spamsink.net> - 2011-05-23 10:35 +0200
      Re: Types in C Keith Thompson <kst-u@mib.org> - 2011-05-23 08:40 -0700
        Re: Types in C Seebs <usenet-nospam@seebs.net> - 2011-05-23 17:19 +0000
          Re: Types in C John Gordon <gordon@panix.com> - 2011-05-23 17:54 +0000
            Re: Types in C Keith Thompson <kst-u@mib.org> - 2011-05-23 11:33 -0700
              Re: Types in C Keith Thompson <kst-u@mib.org> - 2011-05-23 11:44 -0700
            Re: Types in C Seebs <usenet-nospam@seebs.net> - 2011-05-23 19:08 +0000
          Re: Types in C jacob navia <jacob@spamsink.net> - 2011-05-23 20:50 +0200
            Re: Types in C Keith Thompson <kst-u@mib.org> - 2011-05-23 12:11 -0700
              Re: Types in C Seebs <usenet-nospam@seebs.net> - 2011-05-23 19:45 +0000
                Re: Types in C Keith Thompson <kst-u@mib.org> - 2011-05-23 13:03 -0700
                Re: Types in C jacob navia <jacob@spamsink.net> - 2011-05-23 22:25 +0200
                Re: Types in C Keith Thompson <kst-u@mib.org> - 2011-05-23 14:38 -0700
                Re: Types in C jacob navia <jacob@spamsink.net> - 2011-05-23 23:45 +0200
                Re: Types in C Seebs <usenet-nospam@seebs.net> - 2011-05-23 22:02 +0000
                Re: Types in C jacob navia <jacob@spamsink.net> - 2011-05-24 00:10 +0200
                Re: Types in C jacob navia <jacob@spamsink.net> - 2011-05-23 22:12 +0200
                Re: Types in C Keith Thompson <kst-u@mib.org> - 2011-05-23 13:27 -0700
                Re: Types in C jacob navia <jacob@spamsink.net> - 2011-05-23 22:33 +0200
                Re: Types in C Martin Ambuhl <mambuhl@earthlink.net> - 2011-05-24 03:17 -0400
                Re: Types in C jacob navia <jacob@spamsink.net> - 2011-05-24 10:55 +0200
                Re: Types in C Ian Collins <ian-news@hotmail.com> - 2011-05-24 09:29 +1200
                Re: Types in C jacob navia <jacob@spamsink.net> - 2011-05-23 23:42 +0200
                Re: Types in C Ian Collins <ian-news@hotmail.com> - 2011-05-24 09:51 +1200
                Re: Types in C jacob navia <jacob@spamsink.net> - 2011-05-24 00:04 +0200
                Re: Types in C Ian Collins <ian-news@hotmail.com> - 2011-05-24 10:57 +1200
                Re: Types in C David Thompson <dave.thompson2@verizon.net> - 2011-06-01 16:33 -0400
                Re: Types in C Shao Miller <sha0.miller@gmail.com> - 2011-05-23 19:33 -0500
                Re: Types in C Keith Thompson <kst-u@mib.org> - 2011-05-24 08:27 -0700
                Re: Types in C Tim Rentsch <txr@alumni.caltech.edu> - 2011-05-31 00:40 -0700
                Re: Types in C jacob navia <jacob@spamsink.net> - 2011-05-31 11:32 +0200
                Re: Types in C Keith Thompson <kst-u@mib.org> - 2011-05-31 11:30 -0700
                Re: Types in C Tim Rentsch <txr@alumni.caltech.edu> - 2011-06-01 01:23 -0700
                Re: Types in C Uncle Steve <stevet810@gmail.com> - 2011-05-23 16:51 -0400
                Re: Types in C Ian Collins <ian-news@hotmail.com> - 2011-05-24 09:25 +1200
                Re: Types in C jacob navia <jacob@spamsink.net> - 2011-05-23 23:40 +0200
                Re: Types in C Keith Thompson <kst-u@mib.org> - 2011-05-24 08:36 -0700
                Re: Types in C Uncle Steve <stevet810@gmail.com> - 2011-05-23 17:53 -0400
                Re: Types in C Seebs <usenet-nospam@seebs.net> - 2011-05-23 22:24 +0000
                Re: Types in C Uncle Steve <stevet810@gmail.com> - 2011-05-23 19:23 -0400
                Re: Types in C Seebs <usenet-nospam@seebs.net> - 2011-05-23 23:57 +0000
                Re: Types in C Uncle Steve <stevet810@gmail.com> - 2011-05-23 21:22 -0400
                Re: Types in C Seebs <usenet-nospam@seebs.net> - 2011-05-24 03:46 +0000
                Re: Types in C Uncle Steve <stevet810@gmail.com> - 2011-05-24 00:24 -0400
                Re: Types in C Seebs <usenet-nospam@seebs.net> - 2011-05-24 04:44 +0000
                Re: Types in C pete <pfiland@mindspring.com> - 2011-05-24 07:46 -0400
                Re: Types in C James Kuyper <jameskuyper@verizon.net> - 2011-05-24 07:48 -0400
                Re: Types in C Ian Collins <ian-news@hotmail.com> - 2011-05-24 10:35 +1200
                Re: Types in C Seebs <usenet-nospam@seebs.net> - 2011-05-23 22:38 +0000
                Re: Types in C Ian Collins <ian-news@hotmail.com> - 2011-05-24 10:53 +1200
                Re: Types in C Seebs <usenet-nospam@seebs.net> - 2011-05-23 23:17 +0000
                Re: Types in C Ian Collins <ian-news@hotmail.com> - 2011-05-24 11:24 +1200
                Re: Types in C Seebs <usenet-nospam@seebs.net> - 2011-05-23 23:39 +0000
                Re: Types in C jacob navia <jacob@spamsink.net> - 2011-05-24 11:23 +0200
                Re: Types in C Keith Thompson <kst-u@mib.org> - 2011-05-24 08:46 -0700
                Re: Types in C Malcolm McLean <malcolm.mclean5@btinternet.com> - 2011-05-24 09:14 -0700
                Re: Types in C Michael Press <rubrum@pacbell.net> - 2011-05-28 21:50 -0700
                Re: Types in C "io_x" <a@b.c.invalid> - 2011-06-07 19:50 +0200
                Re: Types in C Uncle Steve <stevet810@gmail.com> - 2011-05-23 19:33 -0400
                Re: Types in C Ian Collins <ian-news@hotmail.com> - 2011-05-24 12:03 +1200
                Re: Types in C Uncle Steve <stevet810@gmail.com> - 2011-05-23 21:27 -0400
                Re: Types in C Ian Collins <ian-news@hotmail.com> - 2011-05-24 13:47 +1200
                Re: Types in C Uncle Steve <stevet810@gmail.com> - 2011-05-23 23:45 -0400
                Re: Types in C Keith Thompson <kst-u@mib.org> - 2011-05-24 00:07 -0700
                Re: Types in C James Kuyper <jameskuyper@verizon.net> - 2011-05-24 08:05 -0400
                Re: Types in C Shao Miller <sha0.miller@gmail.com> - 2011-05-23 19:54 -0500
                Re: Types in C Uncle Steve <stevet810@gmail.com> - 2011-05-23 21:03 -0400
                Re: Types in C Shao Miller <sha0.miller@gmail.com> - 2011-05-23 22:12 -0500
                Re: Types in C Uncle Steve <stevet810@gmail.com> - 2011-05-24 00:03 -0400
                Re: Types in C pete <pfiland@mindspring.com> - 2011-05-24 00:19 -0400
                Re: Types in C pete <pfiland@mindspring.com> - 2011-05-24 00:20 -0400
                Re: Types in C Shao Miller <sha0.miller@gmail.com> - 2011-05-24 00:46 -0500
                Re: Types in C pete <pfiland@mindspring.com> - 2011-05-24 07:36 -0400
                Re: Types in C Uncle Steve <stevet810@gmail.com> - 2011-05-24 10:58 -0400
                Re: Types in C Keith Thompson <kst-u@mib.org> - 2011-05-24 09:40 -0700
                Re: Types in C Uncle Steve <stevet810@gmail.com> - 2011-05-24 21:36 -0400
                Re: Types in C David Thompson <dave.thompson2@verizon.net> - 2011-06-01 16:33 -0400
                Re: Types in C Seebs <usenet-nospam@seebs.net> - 2011-05-24 16:50 +0000
                Re: Types in C Uncle Steve <stevet810@gmail.com> - 2011-05-24 21:10 -0400
                Re: Types in C Keith Thompson <kst-u@mib.org> - 2011-05-24 18:19 -0700
                Re: Types in C Uncle Steve <stevet810@gmail.com> - 2011-05-24 21:42 -0400
                Re: Types in C Shao Miller <sha0.miller@gmail.com> - 2011-05-24 23:47 -0500
                Re: Types in C Uncle Steve <stevet810@gmail.com> - 2011-05-25 10:13 -0400
                Re: Types in C Joe Pfeiffer <pfeiffer@cs.nmsu.edu> - 2011-05-24 22:19 -0600
                Re: Types in C Dr Nick <3-nospam@temporary-address.org.uk> - 2011-05-25 07:04 +0100
                Re: Types in C Keith Thompson <kst-u@mib.org> - 2011-05-25 08:53 -0700
                Re: Types in C Joe Pfeiffer <pfeiffer@cs.nmsu.edu> - 2011-05-25 10:11 -0600
                Re: Types in C Keith Thompson <kst-u@mib.org> - 2011-05-24 09:02 -0700
                Re: Types in C James Kuyper <jameskuyper@verizon.net> - 2011-05-24 07:37 -0400
                Re: Types in C Seebs <usenet-nospam@seebs.net> - 2011-05-23 22:02 +0000
                Re: Types in C Uncle Steve <stevet810@gmail.com> - 2011-05-23 18:15 -0400
                Re: Types in C Seebs <usenet-nospam@seebs.net> - 2011-05-23 22:25 +0000
                Re: Types in C Uncle Steve <stevet810@gmail.com> - 2011-05-23 19:39 -0400
                Re: Types in C Seebs <usenet-nospam@seebs.net> - 2011-05-23 23:57 +0000
                Re: Types in C Uncle Steve <stevet810@gmail.com> - 2011-05-23 21:10 -0400
                Re: Types in C Seebs <usenet-nospam@seebs.net> - 2011-05-24 01:58 +0000
                Re: Types in C Uncle Steve <stevet810@gmail.com> - 2011-05-23 23:56 -0400
                Re: Types in C Seebs <usenet-nospam@seebs.net> - 2011-05-24 04:32 +0000
                Re: Types in C "BartC" <bc@freeuk.com> - 2011-05-25 01:29 +0100
                Re: Types in C Shao Miller <sha0.miller@gmail.com> - 2011-05-23 22:20 -0500
                Re: Types in C Shao Miller <sha0.miller@gmail.com> - 2011-05-23 22:42 -0500
                Re: Types in C Uncle Steve <stevet810@gmail.com> - 2011-05-24 00:07 -0400
                Re: Types in C Seebs <usenet-nospam@seebs.net> - 2011-05-24 04:44 +0000
                Re: Types in C Uncle Steve <stevet810@gmail.com> - 2011-05-24 10:24 -0400
                Re: Types in C Seebs <usenet-nospam@seebs.net> - 2011-05-24 16:50 +0000
                Re: Types in C Uncle Steve <stevet810@gmail.com> - 2011-05-24 21:16 -0400
                Re: Types in C Seebs <usenet-nospam@seebs.net> - 2011-05-25 03:36 +0000
                Re: Types in C Shao Miller <sha0.miller@gmail.com> - 2011-05-24 01:26 -0500
                Re: Types in C Uncle Steve <stevet810@gmail.com> - 2011-05-24 11:04 -0400
                Re: Types in C Keith Thompson <kst-u@mib.org> - 2011-05-24 09:06 -0700
            Re: Types in C David Thompson <dave.thompson2@verizon.net> - 2011-06-01 16:33 -0400
  Re: Types in C Marcin Grzegorczyk <mgrzegor@poczta.onet.pl> - 2011-05-30 22:42 +0200
    Re: Types in C Shao Miller <sha0.miller@gmail.com> - 2011-05-30 17:45 -0500
      Re: Types in C Keith Thompson <kst-u@mib.org> - 2011-05-31 08:47 -0700
        Re: Types in C Shao Miller <sha0.miller@gmail.com> - 2011-05-31 13:54 -0400
    Re: Types in C jacob navia <jacob@spamsink.net> - 2011-05-31 00:16 +0200
      Re: Types in C Shao Miller <sha0.miller@gmail.com> - 2011-05-30 18:30 -0500
      Re: Types in C Marcin Grzegorczyk <mgrzegor@poczta.onet.pl> - 2011-06-02 22:44 +0200
        Re: Types in C jacob navia <jacob@spamsink.net> - 2011-06-02 22:49 +0200
          Re: Types in C Keith Thompson <kst-u@mib.org> - 2011-06-02 15:26 -0700

csiph-web