From: Shane Dempsey (sdempsey at domain tssg.wit.ie)
Date: Wed 10 May 2000 - 20:55:29 IST
Hi guys,
Interesting discussion. The statement
int i[10] = {1};
should initialise the array to
{ 1 , 0 , 0 , 0 , ... , 0 }
I am pretty sure that this is defined in the ANSI standard for C.
I could be wrong though. The only compiler that I have to test
it on here is VC++ and that seems to work ( just about )
memset is defined as void *memset(void *dest, int c , size_t count);
and "sets count bytes of dest to the character c".
This seems to suggest that it is indeed a bit pattern as opposed to a
logical value. Not sure exactly what typing ( C types not my clumsy fingers
! )
issues arise here. Explicit casts are probably best.
Also ' : '
( as previously stated )
is definitely non-standard and pretty damn horrible. When
space gets that tight you should just right the fscking thing in
assembler.
Which reminds me that I must get back to those horrible
MS *.asm files. Woe is me ....
...shane
Every now and then, when your life gets complicated and the weasels
start
closing in, the only cure is to load up on heinous chemicals and then
drive like a bastard from Hollywood to Las Vegas ... with the music at
top volume and at least a pint of ether.
-- Hunter S. Thompson, "Fear and Loathing in Las Vegas"
----- Original Message -----
From: "Caolan McNamara" <cmc at domain stardivision.de>
To: <ilug at domain linux.ie>
Sent: Wednesday, May 10, 2000 6:32 PM
Subject: Re: [ILUG] gcc optimisation weirdness?
> >>>>>>>>>>>>>>>>>> Original Message <<<<<<<<<<<<<<<<<<
> On 10.05.00, 18:38:44, Paul Jakma <paulj at domain itg.ie> wrote regarding [ILUG]
gcc
> optimisation weirdness?:
>
> > gcc seems to do weird things to the following:
> > int input, frequency[9];
>
> int input, frequency[10];
>
> you accept a value of 10 for input, you would then index into frequency
> at position frequency[9] unfortunately this is the 10th element and
> frequency is 9 long. Once you go into out of bounds territory then
> anything can happen.
>
> The other comment about the statement
> (f[i])++;
> being invalid is just wrong, thats perfectly legal. Nothing to do with
> compound statements, the brackets are in their guise of simple precedence
> here, the gcc extension would only go into effect if the bracketed
> components do not break down to yield a single lvalue
>
> > PS: is there anyway to initialise an array at declaration time, rather
> > than iterate thru the array and set each element manually? eg something
> > like: int array[9]=0;
>
> int array[9]={0};
> explicitly sets array[0] to 0 , and as an aggregate the remaining
> elements are implicitly set to 0.
> http://www.eskimo.com/~scs/cclass/notes/sx4aa.html
> There is the ugly
> memset(array, 0, 9);
> but its unnecessary. (and there is an obscure argument about memset
> setting a 0 bitpattern vs 0 being a logical 0 but thats an unnecessary
> bit of fluff that we can go into another day)
>
> Setting all chars to a non 0 value forces you back to an explicit listing
> int a[3] = {1, 1, 1}; or back to a memset.
>
> C.
>
> --
> Irish Linux Users' Group: ilug at domain linux.ie
> http://www.linux.ie/mailman/listinfo/ilug for (un)subscription
information.
> List maintainer: listmaster at domain linux.ie
>
>
This archive was generated by hypermail 2.1.6 : Thu 06 Feb 2003 - 13:06:06 GMT