Hi,

Well, it comes from the management of the square braces.

  2["abcde"];

is equivalent to (from the compilers point of view) to

  *(2 + "abcde");

which is
  *("abcde" + 2);

which is the character 'c';

which is definately legal.

There was general agreement from the discussion on this code that anyone 
who wrote code like the above should be fired immediately.


=====================
Yes, with C you can make spaghetti.

However, think carefully. I would suggest that almost any language allows 
you to make spaghetti. There will always be someone on the staff that 
writes code in a fashion that is hard to read and debug.

Great projects have been written in C (which are not spaghetti). The 
reason? The authors worked hard at readability and cleanness etc. This 
takes effort, but pays huge dividends.

Derek.


On Mon, 2 Jul 2007, Volker Kuhlmann wrote:

> > Is the following line of code legal?
> > 
> >   2["abcde"];
> 
> Not for anyone caring about legibility. The string inside the []
> translates into a pointer to an array of char. Pointers as array index
> aren't right, there should be an offset from the base pointer of the
> array, so I'd say, not legal. The 2 is a constant, there should be an
> identifier which gives a pointer to which the array index is added.
> 
> Knowing C, of course any spaghetti goes. So the 2 is the pointer to the
> first element of the array, to which the pointer to the const char
> string array, if it can be converted to integer, is added. So it could
> work. Unfortunately. Or there is hope that newer compilers put a stop to
> this nonsense.
> 
> Volker
> 
> 

-- 
Derek Smithies Ph.D.
IndraNet Technologies Ltd.
Email: [EMAIL PROTECTED]
ph +64 3 365 6485
Web: http://www.indranet-technologies.com/

Reply via email to