Re: Character array initialization
From: Richard Tobin (richard_at_cogsci.ed.ac.uk)
Date: 08/04/04
- Next message: pete: "Re: When to use complex declarations like the following.....?"
- Previous message: j: "Re: Storage space of #defines"
- In reply to: Christian Kandeler: "Character array initialization"
- Next in thread: pete: "Re: Character array initialization"
- Messages sorted by: [ date ] [ thread ] [ subject ] [ author ]
Date: 4 Aug 2004 15:29:29 GMT
In article <2ncd60Fuh2hiU1@uni-berlin.de>,
Christian Kandeler <christian.kandeler@hob.de> wrote:
>That's why it is a mistake to write this:
>
>char s[6] = "123456";
It's *often* a mistake.
But try this:
char s[5] = "123456";
I expect your compilers will generate a diagnostic.
What's the difference? There's no requirement in C that arrays of
characters be null-terminated. There are just a bunch of functions
that expect it. It's quite reasonable to initialize an array of 6
characters with 6 non-null characters. On the other hand, it makes no
sense to initialize an array of 5 characters with 6 characters.
-- Richard
- Next message: pete: "Re: When to use complex declarations like the following.....?"
- Previous message: j: "Re: Storage space of #defines"
- In reply to: Christian Kandeler: "Character array initialization"
- Next in thread: pete: "Re: Character array initialization"
- Messages sorted by: [ date ] [ thread ] [ subject ] [ author ]
Relevant Pages
|