Mail Archives: djgpp/1996/11/16/15:22:31
Elliott Oti wrote:
>
> Hi,
> I've been programming in C for a couple of years now and I thought
> I knew at least the basics pretty well, but this has me stumped.
>
> Why does the following short little program output
>
> 10 <rubbish> <rubbish>
> It's also 10 10 10
>
> instead of
>
> 10 10 10
> It's also 10 10 10
>
> It's not a gcc bug because Borland gives a similar output,
> but -Wall gives absolutely no warnings. So what's wrong?
>
> void Dump(thing *V)
> {
> printf("\n%i %i %i\n",*V[0],*V[1],*V[2]);
It took me a while to get it, but your problem is operator precedence.
That line should read:
printf( "\n%i %i %i\n", (*V)[0], (*V)[1], (*V)[2] );
The reason why should be obvious from this. :)
--
John M. Aldrich, aka Fighteer I <fighteer AT cs DOT com>
-----BEGIN GEEK CODE BLOCK-----
Version: 3.1
GCS d- s+:- a-->? c++>$ U@>++$ p>+ L>++ E>+ W++ N++ o+ K? w(---) O-
M-- V? PS+ PE Y+ PGP- t+(-) 5- X- R+ tv+() b+++ DI++ D++ G e(*)>++++
h!() !r !y+()
------END GEEK CODE BLOCK------
- Raw text -