Consider the following code:
typedef struct { int a; int b; }T1; int main(void) { int a=90,res; T1 m = {10,20}; T1 *p = &m; res = p-->a; printf("res=%d\n",res); return 0; }
if you run it it will display:
res=1
The problem here is because we wrote by mistake an extra dash so instead of writing:
res = p->a;
we wrote:
res=p-->a;
We didn’t get any compilation error because the compiler parsed it as a boolean expression:
if ( p-- > a ) res = 1; else res = 0;
Because we have a local variable ‘a’ and also a struct member we got this pitfall
Conclusion:
Follow conventions for declaring local variables and struct members (for example local with characters only and struct members begins with m_)