0
1

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?

R_15 misra c 2012 example suite

Posted at
#include <stdio.h>
#include <stdlib.h>
#include "mc3_types.h"
#include "mc3_header.h"

/* ==== get_* 系 ==== */
bool get_bool(void) { return false; }
char_t get_char(void) { return 'A'; }
int8_t get_int8(void) { return 0; }
int16_t get_int16(void) { return 0; }
int32_t get_int32(void) { return 0; }
int64_t get_int64(void) { return 0; }
uint8_t get_uint8(void) { return 0u; }
uint16_t get_uint16(void) { return 0u; }
uint32_t get_uint32(void) { return 0u; }
uint64_t get_uint64(void) { return 0u; }
float32_t get_float32(void) { return 0.0f; }
float64_t get_float64(void) { return 0.0; }
float128_t get_float128(void) { return 0.0L; }

bool *get_bool_ptr(void) { static bool b = false; return &b; }
char_t *get_char_ptr(void) { static char_t dummy[] = "dummy"; return dummy; }
int8_t *get_int8_ptr(void) { static int8_t v = 0; return &v; }
int16_t *get_int16_ptr(void) { static int16_t v = 0; return &v; }
int32_t *get_int32_ptr(void) { static int32_t v = 0; return &v; }
int64_t *get_int64_ptr(void) { static int64_t v = 0; return &v; }
uint8_t *get_uint8_ptr(void) { static uint8_t v = 0u; return &v; }
uint16_t *get_uint16_ptr(void) { static uint16_t v = 0u; return &v; }
uint32_t *get_uint32_ptr(void) { static uint32_t v = 0u; return &v; }
uint64_t *get_uint64_ptr(void) { static uint64_t v = 0u; return &v; }
float32_t *get_float32_ptr(void) { static float32_t v = 0.0f; return &v; }
float64_t *get_float64_ptr(void) { static float64_t v = 0.0; return &v; }
float128_t *get_float128_ptr(void) { static float128_t v = 0.0L; return &v; }

enum_t get_enum(void) { return ENUM_0; }

/* ==== use_* 系 ==== */
void use_bool(bool b) { printf("use_bool: %d\n", b); }
void use_char(char_t c) { printf("use_char: %c\n", c); }
void use_int8(int8_t i) { printf("use_int8: %d\n", i); }
void use_int16(int16_t i) { printf("use_int16: %d\n", i); }
void use_int32(int32_t i) { printf("use_int32: %d\n", i); }
void use_int64(int64_t i) { printf("use_int64: %lld\n", (long long)i); }
void use_int128(int128_t i) { printf("use_int128: %lld\n", (long long)i); }
void use_uint8(uint8_t u) { printf("use_uint8: %u\n", u); }
void use_uint16(uint16_t u) { printf("use_uint16: %u\n", u); }
void use_uint32(uint32_t u) { printf("use_uint32: %u\n", u); }
void use_uint64(uint64_t u) { printf("use_uint64: %llu\n", (unsigned long long)u); }
void use_uint128(uint128_t u) { printf("use_uint128: %llu\n", (unsigned long long)u); }
void use_float32(float32_t f) { printf("use_float32: %f\n", f); }
void use_float64(float64_t f) { printf("use_float64: %f\n", f); }
void use_float128(float128_t f) { printf("use_float128: %Lf\n", f); }

void use_void_ptr(void *p) { printf("use_void_ptr: %p\n", p); }
void use_bool_ptr(bool *p) { printf("use_bool_ptr: %p\n", (void*)p); }
void use_char_ptr(char_t *p) { printf("use_char_ptr: %s\n", p); }
void use_int8_ptr(int8_t *p) { printf("use_int8_ptr: %p\n", (void*)p); }
void use_int16_ptr(int16_t *p) { printf("use_int16_ptr: %p\n", (void*)p); }
void use_int32_ptr(int32_t *p) { printf("use_int32_ptr: %p\n", (void*)p); }
void use_int64_ptr(int64_t *p) { printf("use_int64_ptr: %p\n", (void*)p); }
void use_uint8_ptr(uint8_t *p) { printf("use_uint8_ptr: %p\n", (void*)p); }
void use_uint16_ptr(uint16_t *p) { printf("use_uint16_ptr: %p\n", (void*)p); }
void use_uint32_ptr(uint32_t *p) { printf("use_uint32_ptr: %p\n", (void*)p); }
void use_uint64_ptr(uint64_t *p) { printf("use_uint64_ptr: %p\n", (void*)p); }
void use_float32_ptr(float32_t *p) { printf("use_float32_ptr: %p\n", (void*)p); }
void use_float64_ptr(float64_t *p) { printf("use_float64_ptr: %p\n", (void*)p); }
void use_float128_ptr(float128_t *p) { printf("use_float128_ptr: %p\n", (void*)p); }

void use_const_char_ptr(const char_t *p) { printf("use_const_char_ptr: %s\n", p); }

void use_enum(enum_t e) { printf("use_enum: %d\n", e); }
void use_sizet(size_t st) { printf("use_sizet: %zu\n", st); }
void use_ptrdiff(ptrdiff_t pt) { printf("use_ptrdiff: %td\n", pt); }

/* ==== action_* 系 ==== */
void action_1(void) { printf("action_1\n"); }
void action_2(void) { printf("action_2\n"); }
void action_f1(void) { printf("action_f1\n"); }
void action_f2(void) { printf("action_f2\n"); }

/* ==== R_15_04.c 対応関数 ==== */
bool ExitNow(uint32_t e) { (void)e; return false; }
bool BreakNow(uint32_t b) { (void)b; return false; }
bool GotoNow(uint32_t g) { (void)g; return false; }
void KeepGoing(uint32_t k) { printf("KeepGoing: %u\n", k); }

/* ==== R_15_06.c 無限ループ防止 ==== */
bool_t process_data(void) {
    static int count = 0;
    printf("process_data\n");
    count++;
    if (count > 5) {
        return true;  /* 5回でループを抜ける */
    }
    return false;
}

bool_t fn(void) {
    static int count = 0;
    printf("fn called\n");
    count++;
    return (count > 2);  /* 2回で true を返す */
}



bash
gcc R_15_01.c R_15_02.c R_15_03.c R_15_04.c R_15_05.c R_15_06.c R_15_07.c R_15_support.c R_15_system.c mc3_stub.c -o misra_demo


./misra_demo
$ ./misra_demo
use_int32: 3
use_int32: 11
use_int32: 1
KeepGoing: 0
KeepGoing: 1
KeepGoing: 2
KeepGoing: 3
KeepGoing: 4
KeepGoing: 5
KeepGoing: 6
KeepGoing: 7
KeepGoing: 8
KeepGoing: 9
KeepGoing: 10
KeepGoing: 11
KeepGoing: 12
KeepGoing: 13
KeepGoing: 14
KeepGoing: 15
KeepGoing: 16
KeepGoing: 17
KeepGoing: 18
KeepGoing: 19
KeepGoing: 20
KeepGoing: 21
KeepGoing: 22
KeepGoing: 23
KeepGoing: 24
KeepGoing: 25
KeepGoing: 26
KeepGoing: 27
KeepGoing: 28
KeepGoing: 29
KeepGoing: 30
KeepGoing: 31
KeepGoing: 32
KeepGoing: 33
KeepGoing: 34
KeepGoing: 35
KeepGoing: 36
KeepGoing: 37
KeepGoing: 38
KeepGoing: 39
KeepGoing: 40
KeepGoing: 41
KeepGoing: 42
KeepGoing: 43
KeepGoing: 44
KeepGoing: 45
KeepGoing: 46
KeepGoing: 47
KeepGoing: 48
KeepGoing: 49
KeepGoing: 50
KeepGoing: 51
KeepGoing: 52
KeepGoing: 53
KeepGoing: 54
KeepGoing: 55
KeepGoing: 56
KeepGoing: 57
KeepGoing: 58
KeepGoing: 59
KeepGoing: 60
KeepGoing: 61
KeepGoing: 62
KeepGoing: 63
KeepGoing: 64
KeepGoing: 65
KeepGoing: 66
KeepGoing: 67
KeepGoing: 68
KeepGoing: 69
KeepGoing: 70
KeepGoing: 71
KeepGoing: 72
KeepGoing: 73
KeepGoing: 74
KeepGoing: 75
KeepGoing: 76
KeepGoing: 77
KeepGoing: 78
KeepGoing: 79
KeepGoing: 80
KeepGoing: 81
KeepGoing: 82
KeepGoing: 83
KeepGoing: 84
KeepGoing: 85
KeepGoing: 86
KeepGoing: 87
KeepGoing: 88
KeepGoing: 89
KeepGoing: 90
KeepGoing: 91
KeepGoing: 92
KeepGoing: 93
KeepGoing: 94
KeepGoing: 95
KeepGoing: 96
KeepGoing: 97
KeepGoing: 98
KeepGoing: 99
use_uint32: 0
fn called
use_bool: 0
process_data
process_data
process_data
process_data
process_data
process_data
use_int32: 3
use_int32: 11
use_int32: 1
KeepGoing: 0
KeepGoing: 1
KeepGoing: 2
KeepGoing: 3
KeepGoing: 4
KeepGoing: 5
KeepGoing: 6
KeepGoing: 7
KeepGoing: 8
KeepGoing: 9
KeepGoing: 10
KeepGoing: 11
KeepGoing: 12
KeepGoing: 13
KeepGoing: 14
KeepGoing: 15
KeepGoing: 16
KeepGoing: 17
KeepGoing: 18
KeepGoing: 19
KeepGoing: 20
KeepGoing: 21
KeepGoing: 22
KeepGoing: 23
KeepGoing: 24
KeepGoing: 25
KeepGoing: 26
KeepGoing: 27
KeepGoing: 28
KeepGoing: 29
KeepGoing: 30
KeepGoing: 31
KeepGoing: 32
KeepGoing: 33
KeepGoing: 34
KeepGoing: 35
KeepGoing: 36
KeepGoing: 37
KeepGoing: 38
KeepGoing: 39
KeepGoing: 40
KeepGoing: 41
KeepGoing: 42
KeepGoing: 43
KeepGoing: 44
KeepGoing: 45
KeepGoing: 46
KeepGoing: 47
KeepGoing: 48
KeepGoing: 49
KeepGoing: 50
KeepGoing: 51
KeepGoing: 52
KeepGoing: 53
KeepGoing: 54
KeepGoing: 55
KeepGoing: 56
KeepGoing: 57
KeepGoing: 58
KeepGoing: 59
KeepGoing: 60
KeepGoing: 61
KeepGoing: 62
KeepGoing: 63
KeepGoing: 64
KeepGoing: 65
KeepGoing: 66
KeepGoing: 67
KeepGoing: 68
KeepGoing: 69
KeepGoing: 70
KeepGoing: 71
KeepGoing: 72
KeepGoing: 73
KeepGoing: 74
KeepGoing: 75
KeepGoing: 76
KeepGoing: 77
KeepGoing: 78
KeepGoing: 79
KeepGoing: 80
KeepGoing: 81
KeepGoing: 82
KeepGoing: 83
KeepGoing: 84
KeepGoing: 85
KeepGoing: 86
KeepGoing: 87
KeepGoing: 88
KeepGoing: 89
KeepGoing: 90
KeepGoing: 91
KeepGoing: 92
KeepGoing: 93
KeepGoing: 94
KeepGoing: 95
KeepGoing: 96
KeepGoing: 97
KeepGoing: 98
KeepGoing: 99
use_uint32: 0
fn called
use_bool: 0
process_data

comment.c
// ********************************************************************


// R_15_06.c 内の以下の部分で無限ループが発生していたためmc3_stub.cでループを抜けるようにしました。


while ( !data_available )
{
   data_available = process_data ( );
}



// ********************************************************************
0
1
0

Register as a new user and use Qiita more conveniently

  1. You get articles that match your needs
  2. You can efficiently read back useful information
  3. You can use dark theme
What you can do with signing up
0
1

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?