- android - 多次调用 OnPrimaryClipChangedListener
- android - 无法更新 RecyclerView 中的 TextView 字段
- android.database.CursorIndexOutOfBoundsException : Index 0 requested, 光标大小为 0
- android - 使用 AppCompat 时,我们是否需要明确指定其 UI 组件(Spinner、EditText)颜色
我正在为 SQL 代码使用预处理器宏 va_args hack,以允许直接粘贴到 sqlite3.exe 中以进行快速的非构建调试:
#define QUOTE(...) #__VA_ARGS__
char const example[] = QUOTE(
INSERT INTO Some_Table(p, q) VALUES(?, ?);
);
https://stackoverflow.com/a/17996915/1848654
然而,这并不是 __VA_ARGS__
应该使用的方式。特别是我的 SQL 代码包含数百个标记。
__VA_ARGS__
长度的限制是多少(如果有)?
最佳答案
我唯一能找到的是 C99 中的这一点(C11 仍然包含相同的文本):
5.2.4.1 Translation limits
The implementation shall be able to translate and execute at least one program that contains at least one instance of every one of the following limits:13)
- [...]
- 127 arguments in one macro invocation
- [...]
- 4095 characters in a character string literal or wide string literal (after concatenation)
- [...]
[...]
13) Implementations should avoid imposing fixed translation limits whenever possible.
所以根据标准没有固定的限制。您将必须检查您的编译器是否记录了任何限制,或者只是尝试支持您抛给它的任何东西(直到它用完 RAM 或其他东西)。
关于c - 预处理器 __VA_ARGS__ 长度的限制?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/47250287/
我有以下两个宏: #define F1(...) [NSString stringWithFormat:__VA_ARGS__] #define F2(format, ...) [NSString s
我想知道##在这个宏定义中做了什么: #define debug(M, ...) fprintf(stderr,M "\n",##__VA_ARGS __) 我在谷歌上搜索了答案,并得出了以下结果。
C++ preprocessor __VA_ARGS__ number of arguments 那里接受的答案对我不起作用。我试过 MSVC++ 10 和 g++ 3.4.5。 我还将示例压缩成更小
此代码片段是否可移植? 定义: #define log(...) std::cout << __FILE__ << "[" << __LINE__ << "]:" \
在可变参数宏中,#__VA_ARGS__是所有参数的逗号分隔字符串(至少我用 gcc 和 clang 得到了这种行为)。有没有一种方法可以在不解析该字符串的情况下为各个参数创建一个字符串数组? 我正在
我有以下宏: #define MY_FCT1( id, ... ) \ FCT( id,__VA_ARGS__ ); \ 我想创建一个新的来做这样的事情: #de
variadic macro提到了 gcc 的 VA_ARGS。 我做了以下实验。 #define EVAL(f,...) eval(f,build_args(args,__VA_ARGS__ , a
我知道我可以做到: #define MACRO(api, ...) \ bool ret = api(123, ##__VA_ARGS__); 这只是一个示例,它是更复杂解决方案的一部分。关键是我
我正在尝试为数组数据冗余编写一个特殊的类型处理。这个想法是在编译时全局定义和声明一个固定大小的数组,但每个声明的数组的大小都不同。这是想法: array[N] = { el1, el2, el3, .
我正在尝试制作一个类似于此的函数: #define printf_copy(s, ...) printf(s, ##__VA_ARGS__) // acceptable! 但这是一个预处理器,我需
如果我尝试编译以下代码: template void Dummy(const TArgs &...args) { } #define DUMMY(...) Dummy("Hello", ##__VA
我想定义一个宏,例如 - #define log(lognumber,...) logreport(lognumber,__VA_ARGS__) 我想检查 __VA_ARGS__ 用户调用 log
假设我们有以下两个函数: void foo1(int p); void foo2(int p, ...); 我想编写一个宏,根据参数的数量自动扩展为正确的宏。我使用了以下肮脏/黑客的方式,但我很好奇是
假设我有一个宏: #define FOO(a, ...) if (a) foo(a, ## __VA_ARGS__) 这很好用: FOO(a)将转换为 if (a) foo(a) FOO(a, )将转
只是为了了解一点背景知识,这不是一个微不足道的练习!我正在使用 Boost.Python,为了避免大量丑陋的样板代码,我使用宏将函数包装在 Python 包装器类中,以选择性地为该方法调用 Pytho
我正在尝试重新定义可变参数宏以使用 cout 而不是 printf。这是原始代码: #define LOGE(...) PRINT_LEVEL(1, __VA_ARGS__); #define P
我正在尝试将 __ VA_ARGS __ 传递给一个函数。由于某种原因,第一个参数总是错误的(看起来像一个地址): #define PRINTF_ERROR(format, ...) {\
我已经从互联网上下载并重新编译了一个库,结果是由于非法指针地址导致核心转储。 查看源码,涉及的语句有: #define E_DEBUG(level, ...) \ if (err_get_de
我正在开发一个嵌入式应用程序,它使用一个库来连接 SPI NAND 内存芯片。提供的库使用打印功能,作为应用程序开发人员,我必须针对我的特定平台覆盖该功能。 例如,他们在代码中广泛使用函数 print
我正在为 SQL 代码使用预处理器宏 va_args hack,以允许直接粘贴到 sqlite3.exe 中以进行快速的非构建调试: #define QUOTE(...) #__VA_ARGS__ c
我是一名优秀的程序员,十分优秀!