Skip to main content

IAR Embedded Workbench for RH850 3.20.x

MISRAC2012-Dir-4.8

In this section:
Synopsis

(Advisory) If a pointer to a structure or union is never dereferenced within a translation unit, then the implementation of the object should be hidden.

Enabled by default

No

Severity/Certainty

Medium/Medium

mediummedium.png
Full description

The implementation of a structure is unnecessarily exposed to a translation unit.

Coding standards
MISRA C:2012 Dir-4.8

(Advisory) If a pointer to a structure or union is never dereferenced within a translation unit, then the implementation of the object should be hidden

Code examples

The following code example fails the check and will give a warning:

#include "transparent_struct.h"
/*
transparent_struct.h:
struct t_struct {
	int field;
};
*/

#include "transparent_struct_getset.h"
/*
transparent_struct_getset.h:
struct t_struct * get();
void set(struct t_struct *);
*/

void example() {
	struct t_struct * value = get();
	// struct t_struct * is not derefenced
	set(value);
}

The following code example passes the check and will not give a warning about this issue:

#include "opaque_struct.h"
/*
opaque_struct.h:
typedef struct o_struct * structure;
*/

#include "opaque_struct_getset.h"
/*
opaque_struct_getset.h:
structure get();
void set_field(structure, int);
void set(structure);
*/

void example() {
	structure value = get();
	// structure is not derefenced explicitly
	set_field(value, 10);
	set(value);
}