Rule 8.8 clarification

Moderators: misra-c, david ward

Post Reply
anuj1085
Posts: 7
Joined: Mon Feb 09, 2015 7:17 am
Company: TCS

Rule 8.8 clarification

Post by anuj1085 » Tue Feb 10, 2015 10:41 am

Just wanted to clarify the rule, i understand this is non-compliance:
==========================================================
static void xyz();
void xyz() /*Non_compliant */
{
...........
}
==========================================================

But the i have query regarding the following:
==========================================================
void xyz();
static void xyz() /* Is this non-compliance*/
{
...............
}
==========================================================
So in the above case where first the function is declared as extern(by default), would it be non complaint under this rule to define it static?

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

Re: Rule 8.8 clarification

Post by misra-c » Fri Feb 13, 2015 9:52 am

Code: Select all

static void xyz();
void xyz() { .. }
In the first line "xyz" is declared with internal linkage in. In the second line the declaration of "xyz" takes the same linkage as the prior declaration which in this case is internal linkage. [See C99: Section 6.2.2 paras 4 and 5 ]
Both declarations therefore have internal linkage. This is well-defined in C, but violates rule 8.8.

Code: Select all

void xyz();
static void xyz() { .. }
In the first line "xyz" is declared with external linkage, whereas in the second line "xyz" is declared with internal linkage. This is undefined behaviour [ C90: Undef 8, C99: Undef 7 ] and is a violation of rule 1.3
---
Posted by and on behalf of
the MISRA C Working Group

Post Reply

Return to “8.8 Declarations and defnitions”