pointers - MISRA incrementation in C -


while debugging embedded code, came across this:

buffptr = &a[5]; buffendptr = &a[10];  while (buffptr != buffendptr)  {      *buffptr = 0xff;      buffptr  = &buffptr[1];         /*  misra improvement for: buffptr++ */  } 

why construct improvement on (*buffptr)++ ?

there misra rule states pointer math allowed indexing operation.

the pattern have shown poorly executed work-around. ugly/weird/uncommon , based on misunderstanding of purpose of rule. may violate rule.

a better way write code be:

for(i=5; < 10; i++) {     a[i] = 0xff; } 

update 2015-05-20 - since accepted answer here's actual rule violated, courtesy of embedded.kyle:

misra-c:2004, rule 17.4 (required) or misra-c:2012, rule 18.4 (required) array indexing shall allowed form of pointer arithmetic.


Comments

Popular posts from this blog

Email notification in google apps script -

c++ - Difference between pre and post decrement in recursive function argument -

javascript - IE11 incompatibility with jQuery's 'readonly'? -