The program excerpt
int i;
char c;
char* a[]= {"abc","def","ghi"};
/* ... */
i=0;
c=a[i++][i++];
obviously invokes undefined behaviour, because i is modified twice
between sequence points. I was wondering if it would be possible to
define some sort of macro to generate a sequence point, so that
c=seq(a[i++])[i++];
could be written and lead to the behaviour being fully defined. (The
idea is that a sequence point would be introduced after the i++ on the
left was evaluated, forcing i to be incremented before the second i++
even runs and avoiding the UB.) Apart from splitting the statement
into two statements (which would probably be the best way to do this
in practice), is there any portable C89 or C99 way to define seq? (By
the way, if it didn't have to work with multiple data types, would a
function that returns its own argument work?)
--
ais523