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_18 misra c 2012

Last updated at Posted at 2025-07-30
R_18_system.c
/*
 * Release: 2016-01-01
 *
 * Example from MISRA C:2012 ( THIS IS NOT A TEST SUITE )
 *
 * Copyright HORIBA MIRA Limited.
 *
 * See file READ_ME.txt for full copyright, license and release instructions.
 */
#include "misrac2012.h"
#include "mc3_types.h"
#include "mc3_header.h"
char * msg = "R_18 misrac 2012";


int main ( void )
{
  R_18_1 ( );
  R_18_2 ( );
  R_18_3 ( );
  R_18_4 ( );
  R_18_5 ( );
  R_18_6 ( );
  R_18_7 ( );
  R_18_8 ( );

  R_18_main_support ( );
  PR1(msg,s);
  return EXIT_SUCCESS;
}




r18.sh
gcc R_18_01.c  R_18_06_2.c R_18_02.c  R_18_03.c R_18_04.c R_18_05_1.c R_13_05_2.c R_18_06_1.c R_18_07.c R_18_08.c R_13_support.c  R_13_system.c clear_lib.c -o r18.exe
bash
$ ./r18.sh
cc1: fatal error: R_18_05_1.c: No such file or directory
compilation terminated.
R_18_06_1.c: In function ‘func’:
R_18_06_1.c:23:11: warning: function returns address of local variable [-Wreturn-local-addr]
   23 |    return &local_auto; /* Non-compliant - &local_auto is indeterminate
      |           ^~~~~~~~~~~
clear_lib.c:246:17: error: field ‘fn’ declared as a function
  246 |       int32_t * fn(void);
      |                 ^~
clear_lib.c: In function ‘fn’:
clear_lib.c:249:27: warning: returning ‘int32_t * (*)(void)’ {aka ‘int * (*)(void)’} from a function with incompatible return type ‘int32_t *’ {aka ‘int *’} [-Wincompatible-pointer-types]
  249 | int32_t * fn(void){return fn;}
      |                           ^~
clear_lib.c: In function ‘get_struct_fn_ptr’:
clear_lib.c:253:19: warning: returning ‘int32_t * (*)(void)’ {aka ‘int * (*)(void)’} from a function with incompatible return type ‘int32_t *’ {aka ‘int *’} [-Wincompatible-pointer-types]
  253 |         return r13.fn;
      |                ~~~^~~
bash
$ ./r18.sh
R_18_06_1.c: In function ‘func’:
R_18_06_1.c:23:11: warning: function returns address of local variable [-Wreturn-local-addr]
   23 |    return &local_auto; /* Non-compliant - &local_auto is indeterminate
      |           ^~~~~~~~~~~
/usr/bin/ld: /tmp/ccdks4LG.o: in function `R_13_main_support':
R_13_support.c:(.text+0x9): undefined reference to `R_13_1'
/usr/bin/ld: R_13_support.c:(.text+0xe): undefined reference to `R_13_2'
/usr/bin/ld: R_13_support.c:(.text+0x13): undefined reference to `R_13_3'
/usr/bin/ld: R_13_support.c:(.text+0x18): undefined reference to `R_13_4'
/usr/bin/ld: R_13_support.c:(.text+0x1d): undefined reference to `R_13_5'
/usr/bin/ld: R_13_support.c:(.text+0x22): undefined reference to `R_13_6'
/usr/bin/ld: /tmp/ccVTOR4e.o: in function `main':
R_13_system.c:(.text+0x9): undefined reference to `R_13_1'
/usr/bin/ld: R_13_system.c:(.text+0xe): undefined reference to `R_13_2'
/usr/bin/ld: R_13_system.c:(.text+0x13): undefined reference to `R_13_3'
/usr/bin/ld: R_13_system.c:(.text+0x18): undefined reference to `R_13_4'
/usr/bin/ld: R_13_system.c:(.text+0x1d): undefined reference to `R_13_5'
/usr/bin/ld: R_13_system.c:(.text+0x22): undefined reference to `R_13_6'
collect2: error: ld returned 1 exit status
r18.sh
gcc R_18_01.c  R_18_06_2.c R_18_02.c  R_18_03.c R_18_04.c R_18_05.c  R_18_06_1.c R_18_07.c R_18_08.c R_18_support.c  R_18_system.c clear_lib.c -o r18.exe
R_18_system.c
/*
 * Release: 2016-01-01
 *
 * Example from MISRA C:2012 ( THIS IS NOT A TEST SUITE )
 *
 * Copyright HORIBA MIRA Limited.
 *
 * See file READ_ME.txt for full copyright, license and release instructions.
 */
#include "misrac2012.h"
#include "mc3_types.h"
#include "mc3_header.h"
char * msg = "R_18 misrac 2012";


int main ( void )
{
  R_18_1 ( );
  R_18_2 ( );
  R_18_3 ( );
  R_18_4 ( );
  R_18_5 ( );
  R_18_6 ( );
  R_18_7 ( );
  R_18_8 ( );

  R_18_main_support ( );
  PR1(msg,s);
  return EXIT_SUCCESS;
}

/* end of R_18_system.c */
clear_lib.c
// Addition to Example from MISRA C:2012 ( THIS IS NOT A TEST SUITE )
// (c) Dr. Kiyoshi Ogawa 20200901

/* Copyright HORIBA MIRA Limited.
 * See file READ_ME.txt for full copyright, license and release instructions.
*/

#include "mc3_types.h"
#include "mc3_header.h"
#include "misrac2012.h"

#include "D_04_01.h"
#include "D_04_08.h"
#include "D_04_13.h"

bool b1 = true;

bool get_bool ( void ){
        return b1;
}
char_t get_char ( void ){
        return (char_t) b1;
}
int8_t get_int8 ( void ){
        return (int8_t) b1;
}
int16_t get_int16 ( void ){
        return (int16_t) b1;
}
int32_t get_int32 ( void ){
        return (int32_t) b1;
}
int64_t get_int64 ( void ){
        return (int64_t) b1;
}
uint8_t get_uint8 ( void ){
        return (uint8_t) b1;
}
uint16_t get_uint16 ( void ){
        return (uint16_t) b1;
}
uint32_t get_uint32 ( void ){
        return (uint32_t) b1;
}
uint64_t get_uint64 ( void ){
        return (uint64_t) b1;
}
float32_t get_float32 ( void ){
        return (float32_t) b1;
}
uint64_t get_uint64 ( void ){
        return (uint64_t) b1;
}
float32_t get_float32 ( void ){
        return (float32_t) b1;
}
float64_t get_float64 ( void ){
        return (float64_t) b1;
}
float128_t get_float128 ( void ){
        return (float128_t) b1;
}

bool *get_bool_ptr ( void ){
        return & b1 ;
}
char_t *get_char_ptr ( void ){
        return (char_t *) & b1;
}
int8_t *get_int8_ptr ( void ){
        return (int8_t *) & b1;
}
int16_t *get_int16_ptr ( void ){
        return (int16_t * ) & b1;
}
int32_t *get_int32_ptr ( void ){
        return (int32_t *) & b1;
}
int64_t *get_int64_ptr ( void ){
        return (int64_t *) & b1;
}
uint8_t *get_uint8_ptr ( void ){
        return (uint8_t *) & b1;
}
uint16_t *get_uint16_ptr ( void ){
        return (uint16_t * ) & b1;
}
uint32_t *get_uint32_ptr ( void ){
        return (uint32_t *) & b1;
}
uint64_t *get_uint64_ptr ( void ){
        return (uint64_t * ) & b1;
}
float32_t *get_float32_ptr ( void ){
        return (float32_t *) & b1;
}
uint64_t *get_uint64_ptr ( void ){
        return (uint64_t * ) & b1;
}
float32_t *get_float32_ptr ( void ){
        return (float32_t *) & b1;
}
float64_t *get_float64_ptr ( void ){
        return (float64_t * ) & b1;
}
float128_t *get_float128_ptr ( void ){
        return (float128_t *) & b1;
}

enum enum_t{ One, Two, Three};

enum_t get_enum ( void ){
        return (enum_t) One;
}

/* Functions that use a variable */

void use_bool ( bool use_bool_param ){
        use_bool_param++;
}
void use_char ( char_t use_char_param ){
        use_char_param++;
}
void use_int8 ( int8_t use_int8_param ){
        use_int8_param++;
}
void use_int16 ( int16_t use_int16_param ){
        use_int16_param++;
}
void use_int32 ( int32_t use_int32_param ){
        use_int32_param++;
}
void use_int64 ( int64_t use_int64_param ){
        use_int64_param++;
}
void use_int128( int128_t use_int128_param ){
        use_int128_param++;
}
void use_uint8 ( uint8_t use_uint8_param ){
        use_uint8_param++;
}
void use_uint16 ( uint16_t use_uint16_param ){
        use_uint16_param++;
}
void use_uint32 ( uint32_t use_uint32_param ){
        use_uint32_param++;
}
void use_uint64 ( uint64_t use_uint64_param ){
        use_uint64_param++;
}
void use_uint128 ( uint128_t use_uint128_param ){
        use_uint128_param++;
}
void use_float32 ( float32_t use_float32_param ){
        use_float32_param++;
}
void use_float64 ( float64_t use_float64_param ){
        use_float64_param++;
}
void use_float128 ( float128_t use_float128_param ){
        use_float128_param++;
}

void use_void_ptr ( void * void_ptr_param ){
        void_ptr_param++;
}
void use_bool_ptr ( bool *use_bool_ptr_param ){
        use_bool_ptr_param++;
}
void use_char_ptr ( char_t *use_char_ptr_param ){
        use_char_ptr_param++;
}
void use_int8_ptr ( int8_t *use_int8_ptr_param ){
        use_int8_ptr_param++;
}
void use_int16_ptr ( int16_t *use_int16_ptr_param ){
        use_int16_ptr_param++;
}
void use_int32_ptr ( int32_t *use_int32_ptr_param ){
        use_int32_ptr_param++;
}
void use_int64_ptr ( int64_t *use_int64_ptr_param ){
        use_int64_ptr_param++;
}
void use_uint8_ptr ( uint8_t *use_uint8_ptr_param ){
        use_uint8_ptr_param++;
}
void use_uint16_ptr ( uint16_t *use_uint16_ptr_param ){
        use_uint16_ptr_param++;
}
void use_uint32_ptr ( uint32_t *use_uint32_ptr_param ){
        use_uint32_ptr_param++;
}
void use_uint64_ptr ( uint64_t *use_uint64_ptr_param ){
        use_uint64_ptr_param++;
}
void use_float32_ptr ( float32_t *use_float32_ptr_param ){
        use_float32_ptr_param++;
}
void use_float64_ptr ( float64_t *use_float64_ptr_param ){
        use_float64_ptr_param++;
}
void use_float128_ptr ( float128_t *use_float128_ptr_param ){
        use_float128_ptr_param++;
}


void use_const_char_ptr ( const char_t *use_c_char_ptr_param ){
        use_c_char_ptr_param++;
}


void use_enum ( enum_t use_enum_param ){
        use_enum_param++;
}
void use_sizet ( size_t st ){
        st++;
}
void use_ptrdiff ( ptrdiff_t pt ){
        pt++;
}

// D_04_01.h

bool msg_header_valid ( const char * c ){
        return (bool) c++;
}

// D_04_08.h


ptrX pX;
void use_ptrX ( ptrX p ){
        p++;
}

ptrX get_ptrX ( void ){
        return pX;
}

// D_04_13.h

mutex_t mt;

mutex_t mutex_lock ( void ){
        return mt;
}
void mutex_unlock ( mutex_t m ){
        m.count++;
}

// R_13
/*
volatile uint16_t v1=0, v2=1;

int32_t * get_struct_fn_ptr(void);

int32_t * function_pointer=get_struct_fn_ptr;


int32_t * fn(void){return function_pointer;}

struct r13 {
      int32_t * fn(void);
} r13;


int32_t * get_struct_fn_ptr ( void)
{
        return r13.fn;
}
*/
bash

R_18_06_1.c: In function ‘func’:
R_18_06_1.c:23:11: warning: function returns address of local variable [-Wreturn-local-addr]
23 | return &local_auto; /* Non-compliant - &local_auto is indeterminate
| ^~~~~~~~~~~
inst19@teachB:~/misra2/Example-Suite$ ./r18.exe
msg = R_18 misrac 2012


                                   
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?