Path: csiph.com!x330-a1.tempe.blueboxinc.net!usenet.pasdenom.info!news.albasani.net!eternal-september.org!feeder.eternal-september.org!.POSTED!not-for-mail From: Uncle Steve Newsgroups: comp.lang.c Subject: Re: Types in C Date: Tue, 24 May 2011 00:03:40 -0400 Organization: Friends of the Galactic Collective Lines: 120 Message-ID: References: <43d4ef5f7d2b0f9-0f635@gmail.com> <9401m9Ft2pU9@mid.individual.net> <50d915539d62563-19304@gmail.com> Mime-Version: 1.0 Content-Type: text/plain; charset=us-ascii Content-Transfer-Encoding: 8bit Injection-Info: mx04.eternal-september.org; posting-host="job9yP/rmK/fxQbJrcqEcA"; logging-data="22675"; mail-complaints-to="abuse@eternal-september.org"; posting-account="U2FsdGVkX18io8JpEMkEgZJy2NdiObHQ" User-Agent: nn 6.7.3 Content-Length: 4233 Cancel-Lock: sha1:ZnfCFG8Bz2vDb4SRVafLJtfezuM= Xref: x330-a1.tempe.blueboxinc.net comp.lang.c:4663 On Mon, May 23, 2011 at 10:12:02PM -0500, Shao Miller wrote: > On 5/23/2011 8:03 PM, Uncle Steve wrote: > >On Mon, May 23, 2011 at 07:54:57PM -0500, Shao Miller wrote: > >>On 5/23/2011 4:53 PM, 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 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. Structures and unions are > >>>aggregates of basic types (and structures/unions). I believe > >>>incomplete types are a (usually temporary) artifact of the compilation > >>>process and you won't ever see them in a running program. > >> > >>There are function types, too. > >> > >> typedef struct { > >> char uncle[5]; > >> } s_uncle; > >> typedef s_uncle * f_new_uncle(int, const char *, const s_uncle *); > >> static f_new_uncle new_uncle_unsafe; > >> f_new_uncle new_uncle; > >> > >>That function type appears to be user-defined. > > > >Sure, but a function definition is not a basic type. > > Ok, but now you've said "basic type" rather than "\"user defined\" types". > > Beyond that, the second typedef in the example is not a function > definition. It includes the definition of a function type. Ah, sorry. It's getting late and I'm misreading things. > The standard definition in C99, if I'm not mistaken, includes: > > "The meaning of a value stored in an object or returned by a function > is determined by the /type/ of the expression used to access it..." Doesn't that specify when and how a cast occurs in expression evaluation? int function(void) { return(42); } ... long v = function(); So what I gather from the quoted text is that the return value of function() is promoted to long before the assignment occurs. Is that correct? > >It's another > >special case for type-checking the arguments and return value of > >functions. Call it an aggregate because it bears more resemblance to > >a structure than an int. > > Well, "aggregate" goes more like this, if I'm not mistaken: > > "Array and structure types are collectively called /aggregate types/." > > I think that the best argument against "user-defined types" might go > more like: > > "\"user-defined\" does not appear in such-and-such standard of C." > > I think that when you are using "aggregate," that perhaps you mean > "derived." > > "Any number of /derived types/ can be constructed from the object, > function, and incomplete types, as follows..." Sure, I'm happy with 'derived'. > > > >BTW, would you use, say, k_thompson as a variable identifier when you're > >writing > >examples in reply to Keith Thompson? Just curious. > > He has previously and kindly offered that using his first name is > acceptable, so I'd probably use that. Other possibilities include > "foo", "bar", "baz", "cat", "dog". It just seemed odd. Regards, Uncle Steve -- Should a professional politician be charged with molestation if he kisses babies while attending political rallies?