Thread Rating:
  • 0 Vote(s) - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
Rule 8.4 - main function
#1
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.
<t></t>
#2
I would think so, because the signature is mandatory and there is already an exception for main in Dir 4.6.
<t></t>
#3
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:
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.
<t></t>
#4
dg1980, I realise now that by signature, you meant prototype, not category, as I originally interpreted it.
<t></t>
#5
This statement is incorrect:
"I think that the MISRA WG would deem it to have 'no linkage'".
<t></t>
#6
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
#7
MISRA C:2012 TC1 added an Exception to Rule 8.4 for main()

A prototype is not required for main().
Posted by and on behalf of the MISRA C Working Group


Forum Jump:


Users browsing this thread: 2 Guest(s)