I have a C code which I am trying to make it MISRA Compliance.I am getting following error in two different case:
Case 1]note 9075: external symbol 'buf' defined without a prior declaration [MISRA 2012 Rule 8.4, required] uint32_t buf[BUF_SIZE](in main.c);
How can I define it an another way so it will follow MISRA rule ?
Case 2] note 9075: external symbol 'buf' defined without a prior declaration [MISRA 2012 Rule 8.4, required] uint32_t buf[64U];
case1:
header.h
#define BUF_SIZE 64U
test.c
#include "header.h"
uint32_t buf[BUF_SIZE];
case2:
test.c
uint32_t buf[64U];
How can I define it an another way so it will follow MISRA rule ?
If the array is meant to be accessed by code from multiple different files , then put a declaration of it into header.h
:
extern uint32_t buf[BUF_SIZE];
Do not omit the extern
. Do not omit the array size, although standard C permits doing so. Keep the definition already present in the .c file, unmodified.
If the array is meant for use only in the file in which it is declared , then make it static:
static uint32_t buf[BUF_SIZE];
Do not declare it in any header in this case.
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.