Groups | Search | Server Info | Keyboard shortcuts | Login | Register [http] [https] [nntp] [nntps]
Groups > comp.lang.c > #112374
| From | Keith Thompson <kst-u@mib.org> |
|---|---|
| Newsgroups | comp.lang.c |
| Subject | Re: Splitting strings into arrays with sscanf |
| Date | 2017-06-16 13:16 -0700 |
| Organization | None to speak of |
| Message-ID | <lnd1a3k7r8.fsf@kst-u.example.com> (permalink) |
| References | <oi14f9$edg$3@dont-email.me> <oi15e9$g8h$1@dont-email.me> <F1V0B.2767$AG1.2130@fx42.iad> <7oa8kc99v10gnaf66jtumkl1t2q1tqmnh8@4ax.com> <3adc8c75-0602-3641-f9b5-202538bddd4b@verizon.net> |
"James R. Kuyper" <jameskuyper@verizon.net> writes:
> On 06/16/2017 03:03 PM, Barry Schwarz wrote:
>> On Fri, 16 Jun 2017 18:01:09 GMT, scott@slp53.sl.home (Scott Lurndal)
>> wrote:
>>> Lew Pitcher <lew.pitcher@digitalfreehold.ca> writes:
> ...
>>>> Apparently, tcc is expecting an initialization that looks something like
>>>> char data[10][4] = {"","","","","","","","","",""};
>>>
>>> As "" is of type 'char *', the values assigned to the array will likely
>>> not be as expected (i.e. either the high-byte (big-endian systems) or the
>>> low-byte (little-endian systems) of the address to the empty string will
>>> be stored in data, rather than the expected single NUL byte at column 0
>>> of each of the ten rows).
>>
>> When a string literal is used to initialize an array, the value of the
>> literal is placed in the array, not the address of the literal.
>
> char *words[] = {"Are", "you", "sure", "of", "that?"};
The string literal "Are" is used to initialize words[0], which is a
char*, not an array. The array is initialized by the brace-enclosed
initializer as a whole, which *contains* several string literals.
> What you're saying is close to being correct, it just needs a slight
> change to the wording.
Actually his wording is very close to what the Standard says.
C11 6.3.2.1p3 (emphasis added):
Except when it is the operand of the sizeof operator, or the
unary & operator, **or is a string literal used to initialize
an array**, an expression that has type "array of type" is
converted to an expression with type "pointer to type" that
points to the initial element of the array object and is not
an lvalue. If the array object has register storage class,
the behavior is undefined.
(This is from the published C11 standard. The N1570 draft has an
incorrect reference to the _Alignof operator.)
--
Keith Thompson (The_Other_Keith) kst-u@mib.org <http://www.ghoti.net/~kst>
Working, but not speaking, for JetHead Development, Inc.
"We must do something. This is something. Therefore, we must do this."
-- Antony Jay and Jonathan Lynn, "Yes Minister"
Back to comp.lang.c | Previous | Next — Previous in thread | Next in thread | Find similar | Unroll thread
Splitting strings into arrays with sscanf DFS <nospam@dfs.com> - 2017-06-16 13:33 -0400
Re: Splitting strings into arrays with sscanf scott@slp53.sl.home (Scott Lurndal) - 2017-06-16 17:46 +0000
Re: Splitting strings into arrays with sscanf DFS <nospam@dfs.com> - 2017-06-16 14:02 -0400
Re: Splitting strings into arrays with sscanf scott@slp53.sl.home (Scott Lurndal) - 2017-06-16 18:15 +0000
Re: Splitting strings into arrays with sscanf Keith Thompson <kst-u@mib.org> - 2017-06-16 12:28 -0700
Re: Splitting strings into arrays with sscanf Keith Thompson <kst-u@mib.org> - 2017-06-16 12:20 -0700
Re: Splitting strings into arrays with sscanf Lew Pitcher <lew.pitcher@digitalfreehold.ca> - 2017-06-16 13:47 -0400
Re: Splitting strings into arrays with sscanf scott@slp53.sl.home (Scott Lurndal) - 2017-06-16 18:01 +0000
Re: Splitting strings into arrays with sscanf Barry Schwarz <schwarzb@dqel.com> - 2017-06-16 12:03 -0700
Re: Splitting strings into arrays with sscanf "James R. Kuyper" <jameskuyper@verizon.net> - 2017-06-16 15:33 -0400
Re: Splitting strings into arrays with sscanf Keith Thompson <kst-u@mib.org> - 2017-06-16 13:16 -0700
Re: Splitting strings into arrays with sscanf Keith Thompson <kst-u@mib.org> - 2017-06-16 12:31 -0700
Re: Splitting strings into arrays with sscanf "James R. Kuyper" <jameskuyper@verizon.net> - 2017-06-16 15:45 -0400
Re: Splitting strings into arrays with sscanf "James R. Kuyper" <jameskuyper@verizon.net> - 2017-06-16 14:07 -0400
Re: Splitting strings into arrays with sscanf "James R. Kuyper" <jameskuyper@verizon.net> - 2017-06-16 14:22 -0400
Re: Splitting strings into arrays with sscanf DFS <nospam@dfs.com> - 2017-06-16 15:36 -0400
Re: Splitting strings into arrays with sscanf "James R. Kuyper" <jameskuyper@verizon.net> - 2017-06-16 17:17 -0400
Re: Splitting strings into arrays with sscanf Barry Schwarz <schwarzb@dqel.com> - 2017-06-16 12:06 -0700
Re: Splitting strings into arrays with sscanf Real Troll <Real.Troll@Trolls.com> - 2017-06-16 17:30 -0400
Re: Splitting strings into arrays with sscanf ike@iceland.freeshell.org - 2017-06-17 16:49 +0000
Re: Splitting strings into arrays with sscanf Richard Damon <Richard@Damon-Family.org> - 2017-06-17 18:25 -0400
csiph-web