I have embedded system project, which I'm testing with Ceedling (=Unity and Cmock).
In one test case code under test is that simple:
uint32_t zero = eeprom_read_dword((uint32_t*)&non_volatile_zero);
sprintf(output, "%lu", zero);
As embedded system is 8-bit architecture, %lu
must be used in sprintf for formatting 32-bit unsigned int for printing. However, desktop environment (GCC) is used for test build and running of tests (and it's not an option to use embedded build for tests). This causes next warning:
warning: format ‘%lu’ expects argument of type ‘long unsigned int’, but argument 3 has type ‘uint32_t’ {aka ‘unsigned int’} [-Wformat=]
62 sprintf(output, "%lu", zero);
~~^ ~~~~
| |
| uint32_t {aka unsigned int}
long unsigned int
%u
Warning itself is correct in the desktop environment, but false positive from the embedded system point of view.
My question is how to set -Wno-format compiler flag for test build as I have not defined tools-section in project.yml at all as default GCC is used? Or maybe there is even a way to tell ceedling that target system is using 8-bit architecture?
CodePudding user response:
Instead of looking for a way to disable the warning, deal with the issue that the warning is about. That is, use the portable format specifiers from inttypes.h
. These are the most correct to use when printing the stdint.h
types.
#include <inttypes.h>
sprintf(output, "%"PRIu32, zero);
CodePudding user response:
If someone happens to search answer to original question, here is a solution how to add compiler flags for a specified source file without defining whole tools section in project.yml
:
# Adds -Wno-format for sourcefile.c
:flags:
:test:
:compile:
:sourcefile: # use :*: for all sources.
- -Wno-format