Groups | Search | Server Info | Keyboard shortcuts | Login | Register [http] [https] [nntp] [nntps]
Groups > comp.lang.c > #20348 > unrolled thread
| Started by | John Reye <jononanon@googlemail.com> |
|---|---|
| First post | 2012-05-03 14:03 -0700 |
| Last post | 2012-05-04 17:10 -0400 |
| Articles | 14 — 6 participants |
Back to article view | Back to comp.lang.c
Possible occurrences of "char [3]" John Reye <jononanon@googlemail.com> - 2012-05-03 14:03 -0700
Re: Possible occurrences of "char [3]" Ben Pfaff <blp@cs.stanford.edu> - 2012-05-03 14:09 -0700
Re: Possible occurrences of "char [3]" John Reye <jononanon@googlemail.com> - 2012-05-03 14:13 -0700
Re: Possible occurrences of "char [3]" John Reye <jononanon@googlemail.com> - 2012-05-13 05:10 -0700
Re: Possible occurrences of "char [3]" Ben Bacarisse <ben.usenet@bsb.me.uk> - 2012-05-15 03:19 +0100
Re: Possible occurrences of "char [3]" Jens Gustedt <jens.gustedt@loria.fr> - 2012-05-15 22:17 +0200
Re: Possible occurrences of "char [3]" Ben Bacarisse <ben.usenet@bsb.me.uk> - 2012-05-15 21:28 +0100
Re: Possible occurrences of "char [3]" Jens Gustedt <jens.gustedt@loria.fr> - 2012-05-16 08:18 +0200
Re: Possible occurrences of "char [3]" Ben Bacarisse <ben.usenet@bsb.me.uk> - 2012-05-16 12:20 +0100
Re: Possible occurrences of "char [3]" Tim Rentsch <txr@alumni.caltech.edu> - 2012-05-17 14:59 -0700
Re: Possible occurrences of "char [3]" Tim Rentsch <txr@alumni.caltech.edu> - 2012-05-17 14:53 -0700
Re: Possible occurrences of "char [3]" Ben Bacarisse <ben.usenet@bsb.me.uk> - 2012-05-03 22:28 +0100
Re: Possible occurrences of "char [3]" Jens Gustedt <jens.gustedt@loria.fr> - 2012-05-04 09:28 +0200
Re: Possible occurrences of "char [3]" "Scott Fluhrer" <sfluhrer@ix.netcom.com> - 2012-05-04 17:10 -0400
| From | John Reye <jononanon@googlemail.com> |
|---|---|
| Date | 2012-05-03 14:03 -0700 |
| Subject | Possible occurrences of "char [3]" |
| Message-ID | <4af8a9a8-fe7c-4961-8e49-ff02da2a4b6d@m10g2000vbb.googlegroups.com> |
Hi there,
where could the following legally occurr in C code - not counting in
strings ;)
char [3]
I can think only of:
sizeof(char [3]);
Are there any other possibilities?
Thanks.
[toc] | [next] | [standalone]
| From | Ben Pfaff <blp@cs.stanford.edu> |
|---|---|
| Date | 2012-05-03 14:09 -0700 |
| Message-ID | <87lil9nf8c.fsf@blp.benpfaff.org> |
| In reply to | #20348 |
John Reye <jononanon@googlemail.com> writes: > where could the following legally occurr in C code - not counting in > strings ;) > > char [3] void function(char [3]);
[toc] | [prev] | [next] | [standalone]
| From | John Reye <jononanon@googlemail.com> |
|---|---|
| Date | 2012-05-03 14:13 -0700 |
| Subject | Re: Possible occurrences of "char [3]" |
| Message-ID | <28ba14b1-6a7a-4dba-b9c2-13928a51cb54@n5g2000vbf.googlegroups.com> |
| In reply to | #20348 |
In particular: It is never possible to use that is a cast, right? (char [3]) var /* this cast is never allowed, right? */
[toc] | [prev] | [next] | [standalone]
| From | John Reye <jononanon@googlemail.com> |
|---|---|
| Date | 2012-05-13 05:10 -0700 |
| Subject | Re: Possible occurrences of "char [3]" |
| Message-ID | <aa11ebcb-2aa3-41b5-b99b-31aeef293b82@q5g2000yqk.googlegroups.com> |
| In reply to | #20353 |
On 3 Mai, 23:13, John Reye <jonona...@googlemail.com> wrote:
> In particular:
> It is never possible to use that is a cast, right?
>
> (char [3]) var /* this cast is never allowed, right? */
I do actually believe that a cast is possible:
Example
printf("%s\n", (char [3]) {'h', 'i', '\0'} );
[toc] | [prev] | [next] | [standalone]
| From | Ben Bacarisse <ben.usenet@bsb.me.uk> |
|---|---|
| Date | 2012-05-15 03:19 +0100 |
| Subject | Re: Possible occurrences of "char [3]" |
| Message-ID | <0.a75cedbbd295402f03fe.20120515031955BST.874nrip4ms.fsf@bsb.me.uk> |
| In reply to | #20756 |
John Reye <jononanon@googlemail.com> writes:
> On 3 Mai, 23:13, John Reye <jonona...@googlemail.com> wrote:
>> In particular:
>> It is never possible to use that is a cast, right?
>>
>> (char [3]) var /* this cast is never allowed, right? */
>
> I do actually believe that a cast is possible:
> Example
> printf("%s\n", (char [3]) {'h', 'i', '\0'} );
That's not a cast. It's a compound literal.
(Anyone know why that are called that since they need not be compound
and they don't seem to be literals -- at least not like any other C
literals?)
--
Ben.
[toc] | [prev] | [next] | [standalone]
| From | Jens Gustedt <jens.gustedt@loria.fr> |
|---|---|
| Date | 2012-05-15 22:17 +0200 |
| Subject | Re: Possible occurrences of "char [3]" |
| Message-ID | <4FB2B9E5.4020409@loria.fr> |
| In reply to | #20777 |
Am 15.05.2012 04:19, schrieb Ben Bacarisse: > That's not a cast. It's a compound literal. > > (Anyone know why that are called that since they need not be compound > and they don't seem to be literals -- at least not like any other C > literals?) It's a misnomer (like others) a failed attempt to introduce "real" literals for all types of classes. "Real" literals would be given by const qualified register variables in file scope (which are unfortunately not allowed.) My guess is that the analogy is not taken from literals for arithmetic types but from "string literals", which aren't "literals" either, but unmutable objects. Jens
[toc] | [prev] | [next] | [standalone]
| From | Ben Bacarisse <ben.usenet@bsb.me.uk> |
|---|---|
| Date | 2012-05-15 21:28 +0100 |
| Subject | Re: Possible occurrences of "char [3]" |
| Message-ID | <0.7d6d2dade9e190163c1a.20120515212821BST.87liktnq8q.fsf@bsb.me.uk> |
| In reply to | #20821 |
Jens Gustedt <jens.gustedt@loria.fr> writes: > Am 15.05.2012 04:19, schrieb Ben Bacarisse: > >> That's not a cast. It's a compound literal. >> >> (Anyone know why that are called that since they need not be compound >> and they don't seem to be literals -- at least not like any other C >> literals?) > > It's a misnomer (like others) a failed attempt to introduce "real" > literals for all types of classes. "Real" literals would be given by > const qualified register variables in file scope (which are > unfortunately not allowed.) > > My guess is that the analogy is not taken from literals for arithmetic > types but from "string literals", which aren't "literals" either, but > unmutable objects. Yes, there is a similarity there in that both make objects, but string literals are (as you say) immutable which is, in my mind, a key property of a literal. Compound literals are modifiable lvalues. I'd rather they were called "anonymous objects" but that boat has sailed. -- Ben.
[toc] | [prev] | [next] | [standalone]
| From | Jens Gustedt <jens.gustedt@loria.fr> |
|---|---|
| Date | 2012-05-16 08:18 +0200 |
| Subject | Re: Possible occurrences of "char [3]" |
| Message-ID | <4FB346A9.3030006@loria.fr> |
| In reply to | #20823 |
Am 15.05.2012 22:28, schrieb Ben Bacarisse: > Compound literals are modifiable lvalues. I'd rather > they were called "anonymous objects" that would be ambiguous, too, since malloced objects are the same. anonymous automatic variables? > but that boat has sailed. yes, unfortunately Jens
[toc] | [prev] | [next] | [standalone]
| From | Ben Bacarisse <ben.usenet@bsb.me.uk> |
|---|---|
| Date | 2012-05-16 12:20 +0100 |
| Subject | Re: Possible occurrences of "char [3]" |
| Message-ID | <0.81dc265e52c28d844fba.20120516122027BST.87fwb0nzic.fsf@bsb.me.uk> |
| In reply to | #20847 |
Jens Gustedt <jens.gustedt@loria.fr> writes: > Am 15.05.2012 22:28, schrieb Ben Bacarisse: >> Compound literals are modifiable lvalues. I'd rather >> they were called "anonymous objects" > > that would be ambiguous, too, since malloced objects are the same. True. > anonymous automatic variables? > >> but that boat has sailed. > > yes, unfortunately I'll resist the urge to make any other suggestions since it's done and dusted. -- Ben.
[toc] | [prev] | [next] | [standalone]
| From | Tim Rentsch <txr@alumni.caltech.edu> |
|---|---|
| Date | 2012-05-17 14:59 -0700 |
| Subject | Re: Possible occurrences of "char [3]" |
| Message-ID | <kfnwr4a31w3.fsf@x-alumni2.alumni.caltech.edu> |
| In reply to | #20847 |
Jens Gustedt <jens.gustedt@loria.fr> writes: > Am 15.05.2012 22:28, schrieb Ben Bacarisse: >> Compound literals are modifiable lvalues. I'd rather >> they were called "anonymous objects" > > that would be ambiguous, too, since malloced objects are the same. > > anonymous automatic variables? Except compound literals need not be automatic; they also are allowed in top-level initializers. Personally I think "compound literals" is a good choice.
[toc] | [prev] | [next] | [standalone]
| From | Tim Rentsch <txr@alumni.caltech.edu> |
|---|---|
| Date | 2012-05-17 14:53 -0700 |
| Subject | Re: Possible occurrences of "char [3]" |
| Message-ID | <kfn1umi4gq5.fsf@x-alumni2.alumni.caltech.edu> |
| In reply to | #20777 |
Ben Bacarisse <ben.usenet@bsb.me.uk> writes:
> John Reye <jononanon@googlemail.com> writes:
>
>> On 3 Mai, 23:13, John Reye <jonona...@googlemail.com> wrote:
>>> In particular:
>>> It is never possible to use that is a cast, right?
>>>
>>> (char [3]) var /* this cast is never allowed, right? */
>>
>> I do actually believe that a cast is possible:
>> Example
>> printf("%s\n", (char [3]) {'h', 'i', '\0'} );
>
> That's not a cast. It's a compound literal.
>
> (Anyone know why that are called that since they need not be compound
> and they don't seem to be literals -- at least not like any other C
> literals?)
The term makes sense to me. Typically they are used for
"compound" data types (a struct, union, or array); certainly
their most obvious purpose is for "compound" values even if
"ordinary" values are also allowed. As for literal, historically
a "literal" was a memory location (or several) referred to by
giving its contents locally rather than defining it elsewhere and
referring to it using a label. That a 'literal' is an lvalue
rather than an rvalue may seem odd in C but it's consistent with
other uses of the term that predate C (I remember it from various
ancient assembly languages -- IIRC these things were usually
called "literals" but they were just a quick way to refer to a
regular memory location).
[toc] | [prev] | [next] | [standalone]
| From | Ben Bacarisse <ben.usenet@bsb.me.uk> |
|---|---|
| Date | 2012-05-03 22:28 +0100 |
| Message-ID | <0.8fae7f9b2405dece2675.20120503222840BST.87wr4tj6nr.fsf@bsb.me.uk> |
| In reply to | #20348 |
John Reye <jononanon@googlemail.com> writes:
> where could the following legally occurr in C code - not counting in
> strings ;)
and character literals and comments and macro bodies, etc...
> char [3]
>
> I can think only of:
> sizeof(char [3]);
> Are there any other possibilities?
also in compound literals: (char [3]){"ab"}
--
Ben.
[toc] | [prev] | [next] | [standalone]
| From | Jens Gustedt <jens.gustedt@loria.fr> |
|---|---|
| Date | 2012-05-04 09:28 +0200 |
| Message-ID | <4FA3850E.9030307@loria.fr> |
| In reply to | #20348 |
Am 05/03/2012 11:03 PM, schrieb John Reye: > Hi there, > > where could the following legally occurr in C code - not counting in > strings ;) > > char [3] > > > I can think only of: > sizeof(char [3]); > Are there any other possibilities? _Alignof(char[3]) _Alignas(char[3]) and their counteparts with macros alignof and alignas Jens
[toc] | [prev] | [next] | [standalone]
| From | "Scott Fluhrer" <sfluhrer@ix.netcom.com> |
|---|---|
| Date | 2012-05-04 17:10 -0400 |
| Message-ID | <1336165814.2819@rcdn-nntpcache-1> |
| In reply to | #20348 |
"John Reye" <jononanon@googlemail.com> wrote in message news:4af8a9a8-fe7c-4961-8e49-ff02da2a4b6d@m10g2000vbb.googlegroups.com... > Hi there, > > where could the following legally occurr in C code - not counting in > strings ;) > > char [3] > > > I can think only of: > sizeof(char [3]); > Are there any other possibilities? #define char x int char [3] ; :-) -- poncho
[toc] | [prev] | [standalone]
Back to top | Article view | comp.lang.c
csiph-web