Skip to content

Commit b11e4e6

Browse files
Change approach to mimic old mpaland/printf behavior
This avoids the need to deal with compiler optimizations, because we treat the standard library function names as macros and instead use the library version, disabling any unhelpful compiler wizardry. Fixes #27
1 parent 1bf1373 commit b11e4e6

File tree

2 files changed

+7
-24
lines changed

2 files changed

+7
-24
lines changed

src/LibPrintf.cpp

Lines changed: 0 additions & 23 deletions
Original file line numberDiff line numberDiff line change
@@ -25,26 +25,3 @@ extern "C" __attribute__((weak)) void putchar_(char character)
2525
{
2626
print_instance->print(character);
2727
}
28-
29-
#if __GNUC__
30-
/// This works around a problem where GCC is replacing
31-
/// printf("string with no args") with puts("string with no args"), which
32-
/// is not actually implemented in a way that is suitable for us, resulting
33-
/// in an infinite reboot loop or simply not printing that output, depending
34-
/// on my luck.
35-
///
36-
/// This is probably NOT the right way to go about this (expecting it to be undefined
37-
/// behavior, but I have fewer tools available in Arduino land, so I am
38-
/// sticking with this for now.
39-
///
40-
/// If this causes problems in the future, the next thing to try is
41-
/// NOT using the Aliasing option (currently defined in LibPrintf.h) and instead
42-
/// then providing definitions in the mpaland style in our LibPrintf.h header:
43-
/// #define printf printf_
44-
/// #define vprintf vprintf_
45-
/// etc.
46-
extern "C" int puts(const char * str)
47-
{
48-
return printf("%s\n", str);
49-
}
50-
#endif //__GNUC__

src/LibPrintf.h

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,9 +2,15 @@
22
#define ARDUINO_PRINTF_H_
33

44
#include "Print.h"
5-
#define PRINTF_ALIAS_STANDARD_FUNCTION_NAMES 1
65
#include "../extras/printf/printf.h"
76

7+
# define printf printf_
8+
# define sprintf sprintf_
9+
# define vsprintf vsprintf_
10+
# define snprintf snprintf_
11+
# define vsnprintf vsnprintf_
12+
# define vprintf vprintf_
13+
814
// Adds a compatibility definition for those who were using the old library
915
#define _putchar(c) putchar_(c)
1016

0 commit comments

Comments
 (0)