P
per9000
Hi, today I experimented with the increment/++ operator. It seems the
behavior depends on the compiler (I used cl/gcc + cs/mcs) and the
language (I tested C and C#).
Is the ++-operator well defined in all cases? I tested on this for-
loop and the results differ in c/cl, c/gcc and C#/(cs or mcs).
/*
** c1-c8 are all 1 before this loop
** b1-b8 contain only zeros
** a = 1,2,3...16
*/
for (i = 2; i < 5; i++, c3++, ++c7)
{
b1[c1] = a[c1++];
b2[c2++] = a[c2];
b3[c3] = a[c3];
b4[c4++] = a[c4++];
b5[c5] = a[++c5];
b6[++c6] = a[c6];
b7[c7] = a[c7];
b8[++c8] = a[++c8];
}
I understand that this coding-standard (f.x: "b2[c2++] = a[c2];") is
horrible and I will never again use increment on something that is
used more than once in a row. Are there any guides to "good coding
practice" when it comes to increment?
See details here: http://www.pererikstrandberg.se/blog/index.cgi?page=PlusPlusOperator
Thanks,
Per
behavior depends on the compiler (I used cl/gcc + cs/mcs) and the
language (I tested C and C#).
Is the ++-operator well defined in all cases? I tested on this for-
loop and the results differ in c/cl, c/gcc and C#/(cs or mcs).
/*
** c1-c8 are all 1 before this loop
** b1-b8 contain only zeros
** a = 1,2,3...16
*/
for (i = 2; i < 5; i++, c3++, ++c7)
{
b1[c1] = a[c1++];
b2[c2++] = a[c2];
b3[c3] = a[c3];
b4[c4++] = a[c4++];
b5[c5] = a[++c5];
b6[++c6] = a[c6];
b7[c7] = a[c7];
b8[++c8] = a[++c8];
}
I understand that this coding-standard (f.x: "b2[c2++] = a[c2];") is
horrible and I will never again use increment on something that is
used more than once in a row. Are there any guides to "good coding
practice" when it comes to increment?
See details here: http://www.pererikstrandberg.se/blog/index.cgi?page=PlusPlusOperator
Thanks,
Per