我有%rep一个预处理器指令,它创建一个预处理器循环。我想在其中声明标签,可能带有一些串联,但我无法获得正确的语法。
%assign i 0
%rep 64
label_%i: ;this, of course, doesn't work
inc rax
%assign i i+1
%endrep
Run Code Online (Sandbox Code Playgroud)
那么如何强制 NASM 预处理器label_i为每次“迭代”生成呢?
我有一本已经完全预处理的字典,可以输入到 BERT 模型中。然而,我很难将其放入 tf.dataset 中。这就是我的数据集的一个元素:
print(dataset[0])
{'input_ids': <tf.Tensor: shape=(128,), dtype=int64, numpy= array([ 101, 171, 112, 2537, 12293, 131, 11250, 118, 118,
2537, 12293, 131, 11250, 1110, 1126, 1237, 1778, 1326,
1687, 1111, 5957, 1398, 11737, 1118, 8129, 14399, 1105,
3230, 9426, 27277, 119, 1135, 1110, 1103, 1148, 1326,
1872, 4418, 1111, 1115, 1555, 117, 1105, 1103, 1148,
2537, 12293, 1326, 1290, 2537, 12293, 131, 9892, 4803,
1107, 1478, 119, 9617, 4986, 170, 4967, 1196, 1103,
1958, 1104, 1103, 1560, 2537, …Run Code Online (Sandbox Code Playgroud) 我需要将一些特定的警告视为错误,以确保程序按预期运行。例如,具有该[[nodiscard]]属性的函数应始终返回,否则编译器会打印错误。在 Visual Studio (MSVC) 中,可以很容易地通过以下方式做到这一点:
#pragma warning (error: warning_id)
Run Code Online (Sandbox Code Playgroud)
这非常有效。但我在集群上运行此代码,使用 GCC、Clang 或 Intel 编译器,因此我希望实现此代码以便可移植。就像是:
#if defined(_MSC_VER)
#pragma warning (error: 4834)
#elif defined(__GNUC__)
// what here?
#elif defined(__clang__)
// what to put here?
#else
// Another compiler...
#endif
Run Code Online (Sandbox Code Playgroud)
我认为Intel与MSVC类似;在 Clang 中,有一个选项可以将错误视为警告-Wno-error=some_error,这可以反过来帮助我,但可能有太多警告,我宁愿不将其视为错误。
我应该怎么办?
我从[https://www.scs.stanford.edu/~dm/blog/va-opt.html]获得了这个源代码。将 MSVC 与 C++20 一起使用它无法编译,但可以在其他编译器上编译。为什么?我该如何解决这个问题?
`/* compile with:
c++ -std=c++20 -Wall -Werror make_enum.cc -o make_enum
*/
#include <iostream>
#define PARENS ()
// Rescan macro tokens 256 times
#define EXPAND(arg) EXPAND1(EXPAND1(EXPAND1(EXPAND1(arg))))
#define EXPAND1(arg) EXPAND2(EXPAND2(EXPAND2(EXPAND2(arg))))
#define EXPAND2(arg) EXPAND3(EXPAND3(EXPAND3(EXPAND3(arg))))
#define EXPAND3(arg) EXPAND4(EXPAND4(EXPAND4(EXPAND4(arg))))
#define EXPAND4(arg) arg
#define FOR_EACH(macro, ...) \
__VA_OPT__(EXPAND(FOR_EACH_HELPER(macro, __VA_ARGS__)))
#define FOR_EACH_HELPER(macro, a1, ...) \
macro(a1) \
__VA_OPT__(FOR_EACH_AGAIN PARENS (macro, __VA_ARGS__))
#define FOR_EACH_AGAIN() FOR_EACH_HELPER
#define ENUM_CASE(name) case name: return #name;
#define MAKE_ENUM(type, ...) \
enum type { \
__VA_ARGS__ \
}; \ …Run Code Online (Sandbox Code Playgroud) 我有 2 个可变宏,其中一个可以正常编译,另一个则不能:
#define ASSERT(x, ...) assert_log(x, __FILE__, __LINE__, __VA_ARGS__)
#define TRACE (x, ...) trace(x, __FILE__, __LINE__, __VA_ARGS__)
...
libs/defs.h:16:71: error: __VA_ARGS__ can only appear in the expansion of a C99 variadic macro [-Werror]
16 | #define TRACE (x, ...) trace(x, __FILE__, __LINE__, __VA_ARGS__)
| ^
Run Code Online (Sandbox Code Playgroud)
他们宣布的签名:
void assert_log(int, const char*, int, const char* , ...);
void trace(int, const char*, int, const char* , ...);
Run Code Online (Sandbox Code Playgroud)
编译标志:
CFLAGS= \
-Wextra \
-Werror \
-Wall \
-Wfloat-equal \
-Wundef \
-Wshadow \ …Run Code Online (Sandbox Code Playgroud) 我有一个perl脚本我想在gcc正常处理之前过滤我的cpp/h文件 - 基本上作为一个额外的预处理步骤.是否有捷径可寻?我意识到我可以将cpp文件提供给脚本并让gcc读取stdin的输出,但这对头文件没有帮助.
我怎么能告诉m4 patsubstr用空格替换字符串中的所有换行符?
我试过了:
patsubst(MULTI_LINE_STR_DEFINE,`\n',` ')
Run Code Online (Sandbox Code Playgroud)
和
patsubst(MULTI_LINE_STR_DEFINE,`\\n',` ')
Run Code Online (Sandbox Code Playgroud) 我确信这可能非常容易(或者它无法完成),但我似乎无法找到任何东西.
在我的一个.h文件中,我需要确定该应用程序是在iPad还是iPhone上运行.然后相应地更改#define的值.
理想情况下,我会这样看起来像这样:
#if UI_USER_INTERFACE_IDIOM() == UIUserInterfaceIdiomPhone
#define deltaX 10.0
#define theda 15.0
#define threshHold 267.0
#endif
#if UI_USER_INTERFACE_IDIOM() == UIUserInterfaceIdiomPad
#define deltaX 78.1
#define theda 67.2
#define threshHold 453.0
#endif
Run Code Online (Sandbox Code Playgroud)
我不知道该使用什么,非常感谢任何帮助.
感谢您的时间!
我有以有序方式命名的变量,i1,i2,i3,...我试图在运行时使用变量名称的数字部分访问这些变量.
这是我尝试用于此问题的代码.它无法正常工作.
#include <iostream>
using namespace std;
#define CreateVariable(c,v) c##v
int main()
{
int i1(11), i2(22), i3(33), i4(44), i5(55);
cout << CreateVariable(i, 3) << endl; // This is working and prints "33"
int k;
cin >> k; // suppose user input '5'
if (k > 0 && k < 6)
cout << CreateVariable(i, k) << endl; // This is not working
return 0;
}
Run Code Online (Sandbox Code Playgroud)
是否有可能在C++中实现这一点?
我正在尝试使用#if检查宏和枚举是否相等。即使两者的值相同,检查也会失败。为什么?
使用#define NUMBER 2创建了一个宏。创建了一个包含值2的条目的枚举。使用#if比较了两者。比较宏与2通过。但是将宏与枚举进行比较失败。
#include <stdio.h>
#define NUMBER 2
enum numbers
{
zero = 0,
one,
two,
three
};
int main ()
{
printf("NUMBER: %x and two: %x\n", NUMBER, two);
#if NUMBER == two
printf("#1-------PASS\n");
#else
printf("#1--------FAIL\n");
#endif
#if NUMBER == 2
printf("#2-------PASS\n");
#else
printf("#2--------FAIL\n");
#endif
if (NUMBER == two)
printf("#3-------PASS\n");
else
printf("#3--------FAIL\n");
}
Run Code Online (Sandbox Code Playgroud)
我期望这三种情况都能通过。实际结果:
NUMBER: 2 and two: 2
#1--------FAIL
#2-------PASS
#3-------PASS
Run Code Online (Sandbox Code Playgroud)