Question about 14.2 and the controlling variable

Moderators: misra-c, david ward

Post Reply
triboix
Posts: 3
Joined: Fri May 27, 2011 10:19 am
Company: Falcon One Ltd

Question about 14.2 and the controlling variable

Post by triboix » Tue Feb 23, 2016 9:43 am

Hello,

14.2 states that the "controlling variable" must be of essentially boolean type.

Does that mean that the following code is non-compliant?

Code: Select all

struct stuff
{
    uint32_t id;
};
struct stuff stuff_array[MAXSTUFF];

struct stuff* stuff_lookup(uint32_t id)
{
    uint8_t i;
    struct stuff* found = NULL;
    for (i = 0; (i < MAXSTUFF) && (found == NULL); i++) {
        if (stuff_array[i].id == id) {
            found = &(stuff_array[i]);
        }
    }
    return found;
}
Thanks a lot for any help!

misra-c
Posts: 569
Joined: Thu Jan 05, 2006 1:11 pm

Re: Question about 14.2 and the controlling variable

Post by misra-c » Thu Mar 03, 2016 8:17 am

Rule 14.2 includes the following statements:
Second clause which
* shall use the loop counter and optionally loop control flags
A loop control flag is defined as a single identifier denoting an object with essentially Boolean type that is used in the second clause.
"found" does not meet the criteria for a loop control flag and therefore is non-compliant with rule 14.2
---
Posted by and on behalf of
the MISRA C Working Group

triboix
Posts: 3
Joined: Fri May 27, 2011 10:19 am
Company: Falcon One Ltd

Re: Question about 14.2 and the controlling variable

Post by triboix » Sun Mar 06, 2016 7:36 am

misra-c wrote:Rule 14.2 includes the following statements:
Second clause which
* shall use the loop counter and optionally loop control flags
A loop control flag is defined as a single identifier denoting an object with essentially Boolean type that is used in the second clause.
"found" does not meet the criteria for a loop control flag and therefore is non-compliant with rule 14.2
All right, thanks a lot for the clarification!

Post Reply

Return to “8.14 Control statement expressions”