Rule 8.4 - main function

Moderators: misra-c, david ward

Post Reply
delta_controls
Posts: 15
Joined: Wed Feb 03, 2016 2:15 pm
Company: Delta Controls Ltd

Rule 8.4 - main function

Post by delta_controls » Wed Apr 20, 2016 5:44 pm

Should this rule have an exception for main? I can't see how main is automatically excluded from this rule. Is the expectation that a prototype is provided for main?

Thanks.

dg1980
Posts: 109
Joined: Wed Apr 27, 2016 2:33 pm
Company: Elektrobit Automotive GmbH

Re: Rule 8.4 - main function

Post by dg1980 » Fri Apr 29, 2016 10:08 am

I would think so, because the signature is mandatory and there is already an exception for main in Dir 4.6.

delta_controls
Posts: 15
Joined: Wed Feb 03, 2016 2:15 pm
Company: Delta Controls Ltd

Re: Rule 8.4 - main function

Post by delta_controls » Thu May 05, 2016 1:15 pm

Rule 8.4 is required, not mandatory. Directive 4.6 isn't relevant here, as it isn't concerned with prior declaration.

Although main has external linkage, I think that the MISRA WG would deem it to have 'no linkage'. The rule and its rationale don't really apply to main, as it isn't called by another translation unit.

Going by the exact wording of the rule, however, I'm not sure whether the following is necessary to avoid a formal deviation:

Code: Select all

int main(void);

int main(void)
{
    ...
}
I think that this would be confusing to someone maintaining the code.

Also, when I wrote 'prototype' in the original post, I really meant declaration in prototype form.

delta_controls
Posts: 15
Joined: Wed Feb 03, 2016 2:15 pm
Company: Delta Controls Ltd

Re: Rule 8.4 - main function

Post by delta_controls » Thu May 05, 2016 4:56 pm

dg1980, I realise now that by signature, you meant prototype, not category, as I originally interpreted it.

delta_controls
Posts: 15
Joined: Wed Feb 03, 2016 2:15 pm
Company: Delta Controls Ltd

Re: Rule 8.4 - main function

Post by delta_controls » Tue May 10, 2016 3:16 pm

This statement is incorrect:
"I think that the MISRA WG would deem it to have 'no linkage'".

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

Re: Rule 8.4 - main function

Post by misra-c » Fri May 13, 2016 1:47 pm

Thank you for drawing our attention to this question. It was not the intention of the MISRA-C working group that rule 8.4 should apply to "main". We will be issuing a clarification.

In summary, a "main" function must contain a prototyped definition, but need not have a separate declaration.
---
Posted by and on behalf of
the MISRA C Working Group

Post Reply

Return to “8.8 Declarations and defnitions”