MISRA Discussion Forums
Rule 8.4 - main function - Printable Version

+- MISRA Discussion Forums (https://forum.misra.org.uk)
+-- Forum: MISRA C (https://forum.misra.org.uk/forumdisplay.php?fid=4)
+--- Forum: MISRA C:2012 and MISRA C:2023 guidelines (https://forum.misra.org.uk/forumdisplay.php?fid=21)
+---- Forum: 8.8 Declarations and defnitions (https://forum.misra.org.uk/forumdisplay.php?fid=163)
+---- Thread: Rule 8.4 - main function (/showthread.php?tid=1237)



Rule 8.4 - main function - delta_controls - 20-04-2016

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.


Re: Rule 8.4 - main function - dg1980 - 29-04-2016

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


Re: Rule 8.4 - main function - delta_controls - 05-05-2016

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.


Re: Rule 8.4 - main function - delta_controls - 05-05-2016

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


Re: Rule 8.4 - main function - delta_controls - 10-05-2016

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


Re: Rule 8.4 - main function - misra-c - 13-05-2016

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.