MISRA C:2004 rule 19.4 / extension

6.19 Preprocessing Directives

Moderators: misra-c, david ward

Posts: 1
Joined: Tue Sep 25, 2007 12:06 pm

MISRA C:2004 rule 19.4 / extension

Post by Laessle » Wed Sep 26, 2007 6:59 am

In our code we want to use generic macros of kind

#define macro(a) int array[2] = {a, a};

unfortunately a do-while-zero loop does not helps, cause defined objects are only known within the loop.

So we would like to ask for a further exception of the described kind.

In the attachment you will find an example to demostrate the intention of such macros.
The program reads values of an Analog Digital Converter (via SPI) and writes modified values to a Pulswidth Generator (also via SPI).
All transfers are coded in an array (Transfer_List). The contents of the array depends on the hardware (baudrate, data-format) and the tranfer-typ (read, write
number of values). The C-file has no hardware dependant function. All hardware specific settings are encapsulated in the macro Create_Transfer_List.
Modifying the hardware only needs to modify the macro. Further I/Os can be implemented very easily.

We would appreciate your positve response.

Mit freundlichen Grüßen/Best regards,

Hans-Peter Lässle
Control Systems

Continental Teves AG & Co. oHG
Guerickestr. 7, D-60488 Frankfurt am Main
P.O. Box 900120, D-60441 Frankfurt am Main

Telefon/Phone: 0049 69 7603-5418
Telefax: 0049 69 7603-3990
E-Mail: [email protected]

Continental Teves AG & Co. oHG, Guerickestr. 7, D-60488 Frankfurt am Main
Sitz der Gesellschaft/Registered Office: Frankfurt am Main, Registergericht/Registered Court: Amtsgericht Frankfurt am Main HR A 27047, USt.-ID-Nr./VAT-ID-No. DE 112160365
Gesellschafter/Shareholders: Continental Aktiengesellschaft (geschäftsführend/managing)
Vorsitzender des Aufsichtsrats/Chairman of the Supervisory Board: Dr. Hubertus von Grünberg
Vorstand/Executive Board: Manfred Wennemer (Vorsitzender/Chairman), Dr. Alan Hippe, Gerhard Lerch, Dr. Karl-Thomas Neumann, Dr. Hans-Joachim Nikolin, Heinz-Gerhard Wente, William L. Kozyra (stv./Deputy)
Sitz der Gesellschaft/Registered Office: Hannover, Registergericht/Registered Court: Amtsgericht Hannover HR B 3527
Continental Teves UK Ltd., Company Number 00700225, Ebbw Vale, Wales, Großbritannien/Great Britain
Proprietary and confidential. Distribution only by express authority of Continental AG or its subsidiaries.
(1.08 KiB) Downloaded 1129 times
(1.47 KiB) Downloaded 1263 times
A procedure for Object_c.pdf
(70.26 KiB) Downloaded 1120 times

Posts: 572
Joined: Thu Jan 05, 2006 1:11 pm

Post by misra-c » Tue Dec 11, 2007 10:42 am

This use of macros requires a deviation to be raised.

Where such use of macros creates clarity, its use is reasonable.

Unconstrained use of macros can create complex code which may lead to unexpected behaviour. This rule attempts to constrain the use of macros to simple contructs. Well designed use of complex macros is possible, and can be justified using a deviation. Examination of the post-processed code is recommended.

The use of macros will be reconsidered for MISRA-C3.
Posted by and on behalf of
the MISRA C Working Group


Return to “6.19 Preprocessing Directives”