MISRA C:2012 Rule 22.7
The macro EOF shall only be compared with the unmodified return
			value from any Standard Library function capable of returning
			EOF
Description
Rule Definition
The macro EOF shall only be compared with the
					unmodified return value from any Standard Library function capable of returning
						EOF.1
      
This rule comes from MISRA C™: 2012 Amendment 1.
Rationale
The EOF value returned by a standard library function can become
				indistinguishable from a valid character code if the value returned is converted to
				another type. In such cases, testing the converted value against
					EOF does not reliably determine whether the end of the file
				has been reached or if an error has occurred.
To determine the end of file reliably, use the function feof() or
					ferror().
Polyspace Implementation
Polyspace® reports a violation of this rule if these events happen in a sequence:
- A standard library function that can return - EOFis called.
- The return value of the function is then converted to a different type. This conversion can happen over several steps. 
- The converted return value is then compared to the macro - EOF.
Troubleshooting
If you expect a rule violation but do not see it, refer to Diagnose Why Coding Standard Violations Do Not Appear as Expected.
Examples
Check Information
| Group: Resources | 
| Category: Required | 
| AGC Category: Required | 
Version History
Introduced in R2017a1 All MISRA coding rules and directives are © Copyright The MISRA Consortium Limited 2021.
The MISRA coding standards referenced in the Polyspace Bug Finder™ documentation are from the following MISRA standards:
- MISRA C:2004 
- MISRA C:2012 
- MISRA C:2023 
- MISRA C++:2008 
- MISRA C++:2023 
MISRA and MISRA C are registered trademarks of The MISRA Consortium Limited 2021.