Doubts about Rule 21.3 and 21.8

Moderators: misra-c, david ward

chenzhuowansui
Posts: 2
Joined: Wed Feb 20, 2019 5:59 am
Company: Synopsys

Doubts about Rule 21.3 and 21.8

Postby chenzhuowansui » Thu Feb 21, 2019 2:32 am

Hello,

We have some doubts about Rule 21.3 and Rule 21.8, please help clarify

Rule 21.3 The memory allocation and deallocation functions of <stdlib.h> shall not be used
Rule 21.8 The library functions abort, exit, getenv and system of <stdlib.h> shall not be used

From the titles and Rationale of these two rules, they are talking about only functions with the forbidden identifiers, but in the Amplification of these two rules, all these identifiers and macros are forbidden including using these identifiers to define variables or fields of structs. So my question is that can we use these identifiers in the following cases:

Code: Select all

int free = 0; //Violate Rule 21.3?
struct s {
    int free;   //Violate Rule 21.3?
    int malloc; //Violate Rule 21.3?
    int exit; //Violate Rule 21.8?
    };


Please help clarify, thanks a lot!

chenzhuowansui
Posts: 2
Joined: Wed Feb 20, 2019 5:59 am
Company: Synopsys

Re: Doubts about Rule 21.3 and 21.8

Postby chenzhuowansui » Tue Feb 26, 2019 6:24 am

Also, how about accessing the fields with the forbidden identifiers of a struct, like

Code: Select all

printf("%s %c %d %f %f\n", p.name, p.free, p.exit, p.height, p.weight); //Violate Rule 21.3(free) and Rule 21.8(exit)?

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

Re: Doubts about Rule 21.3 and 21.8

Postby misra-c » Wed Jun 12, 2019 8:27 am

Rule 21.3 restricts the use of the functions malloc etc: as defined in stdlib.h. The amplification recognises that malloc etc: may be implemented either as a function or as macro in stdlib.h. The same comment applies to rule 21.8. None of your examples violate rule 21.3 or rule 21.8.

However your examples do violate rule 21.2 as they are declarations of reserved identifiers. The Amplification of rule 21.1 (referred to in rule 21.2) includes in its list of reserved identifiers the "identifiers in file scope described in Section 7, Library" of The Standard. Rule 21.2 applies even if stdlib.h is not included.
---
Posted by and on behalf of
the MISRA C Working Group


Return to “8.21 Standard libraries”

Who is online

Users browsing this forum: No registered users and 0 guests