Welcome to mirror list, hosted at ThFree Co, Russian Federation.

github.com/littlefs-project/littlefs.git - Unnamed repository; edit this file 'description' to name the repository.
summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorJohn Hemmick <33430538+hemmick@users.noreply.github.com>2019-11-05 23:43:02 +0300
committerChristopher Haster <chaster@utexas.edu>2020-03-30 05:58:49 +0300
commit6372f515fe59616bd7e00ca7bcce762c05ab029b (patch)
treee8e044c70dd44a7e168c3c7056465645f2378778
parent6b65737715039ef92d348014316b575b52547019 (diff)
Allow debug prints without __VA_ARGS__
__VA_ARGS__ are frustrating in C. Even for their main purpose (printf), they fall short in that they don't have a _portable_ way to have zero arguments after the format string in a printf call. Even if we detect compilers and use ##__VA_ARGS__ where available, GCC emits a warning with -pedantic that is _impossible_ to explicitly disable. This commit contains the best solution we can think of. A bit of indirection that adds a hidden "%s" % "" to the end of the format string. This solution does not work everywhere as it has a runtime cost, but it is hopefully ok for debug statements.
-rw-r--r--lfs_util.h28
1 files changed, 16 insertions, 12 deletions
diff --git a/lfs_util.h b/lfs_util.h
index 80fab55..2544bc9 100644
--- a/lfs_util.h
+++ b/lfs_util.h
@@ -50,31 +50,35 @@ extern "C"
// Logging functions
#ifdef LFS_YES_TRACE
-#define LFS_TRACE(fmt, ...) \
- printf("lfs_trace:%d: " fmt "\n", __LINE__, __VA_ARGS__)
+#define LFS_TRACE_(fmt, ...) \
+ printf("lfs_trace:%d: " fmt "%s\n", __LINE__, __VA_ARGS__)
+#define LFS_TRACE(...) LFS_TRACE_(__VA_ARGS__, "")
#else
-#define LFS_TRACE(fmt, ...)
+#define LFS_TRACE(...)
#endif
#ifndef LFS_NO_DEBUG
-#define LFS_DEBUG(fmt, ...) \
- printf("lfs_debug:%d: " fmt "\n", __LINE__, __VA_ARGS__)
+#define LFS_DEBUG_(fmt, ...) \
+ printf("lfs_debug:%d: " fmt "%s\n", __LINE__, __VA_ARGS__)
+#define LFS_DEBUG(...) LFS_DEBUG_(__VA_ARGS__, "")
#else
-#define LFS_DEBUG(fmt, ...)
+#define LFS_DEBUG(...)
#endif
#ifndef LFS_NO_WARN
-#define LFS_WARN(fmt, ...) \
- printf("lfs_warn:%d: " fmt "\n", __LINE__, __VA_ARGS__)
+#define LFS_WARN_(fmt, ...) \
+ printf("lfs_warn:%d: " fmt "%s\n", __LINE__, __VA_ARGS__)
+#define LFS_WARN(...) LFS_WARN_(__VA_ARGS__, "")
#else
-#define LFS_WARN(fmt, ...)
+#define LFS_WARN(...)
#endif
#ifndef LFS_NO_ERROR
-#define LFS_ERROR(fmt, ...) \
- printf("lfs_error:%d: " fmt "\n", __LINE__, __VA_ARGS__)
+#define LFS_ERROR_(fmt, ...) \
+ printf("lfs_error:%d: " fmt "%s\n", __LINE__, __VA_ARGS__)
+#define LFS_ERROR(...) LFS_ERROR_(__VA_ARGS__, "")
#else
-#define LFS_ERROR(fmt, ...)
+#define LFS_ERROR(...)
#endif
// Runtime assertions