Skip to content

Commit 29b0042

Browse files
Add ability to remove all printf-related functions from a program.
Fixes #33
1 parent c830d06 commit 29b0042

File tree

3 files changed

+21
-1
lines changed

3 files changed

+21
-1
lines changed

README.md

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -47,6 +47,8 @@ See [advanced_usage.md](advanced_usage.md).
4747

4848
If memory footprint is critical, you can disable library features using compiler definitions. Available controls are:
4949

50+
* `PRINTF_DISABLE_ALL`
51+
- Remove all `printf` calls from the program
5052
* `PRINTF_NTOA_BUFFER_SIZE` (unsigned integer)
5153
* 'ntoa' conversion buffer size, this must be big enough to hold one converted numeric number including padded zeros (dynamically created on stack)
5254
* Default: 32 bytes

src/LibPrintf.cpp

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,6 @@
11
#include "LibPrintf.h"
2+
3+
#ifndef PRINTF_DISABLE_ALL
24
#include "Arduino.h"
35

46
#ifdef __AVR__
@@ -25,3 +27,5 @@ extern "C" __attribute__((weak)) void putchar_(char character)
2527
{
2628
print_instance->print(character);
2729
}
30+
31+
#endif // PRINTF_DISABLE_ALL

src/LibPrintf.h

Lines changed: 15 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,19 @@
11
#ifndef ARDUINO_PRINTF_H_
22
#define ARDUINO_PRINTF_H_
33

4+
#ifdef PRINTF_DISABLE_ALL
5+
6+
#define printf(...)
7+
#define sprintf(...)
8+
#define vsprintf(...)
9+
#define snprintf(...)
10+
#define vsnprintf(...)
11+
#define vprintf(...)
12+
13+
#define printf_init(...)
14+
15+
#else // printf is enabled
16+
417
#include "Print.h"
518
#include "../extras/printf/printf.h"
619

@@ -24,6 +37,7 @@
2437
void printf_init(arduino::Print& StreamClass);
2538
#else
2639
void printf_init(Print& StreamClass);
27-
#endif
40+
#endif // __AVR_ATmega4809__
2841

42+
#endif // PRINTF_DISABLE_ALL
2943
#endif //ARDUINO_PRINTF_H_

0 commit comments

Comments
 (0)