"rio" <a@[EMAIL PROTECTED]
> writes:
> "arnuld" <sunrise@[EMAIL PROTECTED]
> ha scritto nel messaggio
> news:pan.2008.05.07.03.11.12.336850@[EMAIL PROTECTED]
>>> On Mon, 05 May 2008 15:17:44 -0700, Peter Nilsson wrote:
>>
>>> You need to be careful though of situations like...
>>>
>>> char foo[5] = "dudes";
>>>
>>> C, unlike C++, allows such an initialisation. There is no
>>> terminating null stored as there is no room for it.
>>
>> yes and you get garbage on the screen:
>>
>> #include <stdio.h>
>>
>> int main( void )
>> {
>> char oye[2] = "ok";
>
> is it not better oye[4] = "ok"; ?
> "ok" is o+k+\0
Not to illustrate the point, no. Both Peter Nilsson and Arnuld posted
code that has an array that is not a string, and in both cases it was
deliberate.
If you want to fix the problem, it is hard to beat 'char oye[] = "ok";'
since you then don't need a size. If you must have a size, anything
other than 3 will be mildly confusing in this example.
>> --
>> http://lispmachine.wordpress.com/
<snip>
Best to trim your replies a bit more. In particular, remove sig blocks
unless you are commenting on them.
--
Ben.


|