标签: preprocessor-directive

如何使用 C# 中的预处理器指令仅在 Windows 10 上执行一些代码?

如何在 .NET 中使用预处理器指令(如 #define)在 windows10 上执行一些代码?不是例如在windows7上吗?

.net c# preprocessor-directive

2
推荐指数
1
解决办法
584
查看次数

有没有办法定义包含预处理器指令的预处理器宏?

我想指示编译器使用如下代码展开一些循环。太长了,我不想复制粘贴。

#define 语句可以定义预处理器宏吗?

我试过这个:

#define foo \
    #ifdef __GNUC__                                             \
        #if __GNUC__ >= 8                                       \
            #pragma GCC unroll 128                              \
            #pragma GCC ivdep                                   \
        #endif                                                  \
    #endif                                                      \
    #ifdef __clang__                                            \
        #pragma clang loop vectorize(enable) interleave(enable) \
    #endif     
Run Code Online (Sandbox Code Playgroud)

但是当我foo在代码中使用时cpp显示它无效扩展为:

 #ifdef 4 #if 4 >= 8 #pragma GCC unroll 128 #pragma GCC ivdep #endif #endif #ifdef __clang__ #pragma clang loop vectorize(enable) interleave(enable) #endif
 #ifdef 4 #if 4 >= 8 #pragma GCC unroll 128 #pragma GCC ivdep #endif …
Run Code Online (Sandbox Code Playgroud)

c macros pragma c-preprocessor preprocessor-directive

2
推荐指数
1
解决办法
385
查看次数

编译器应该为#define的某些组合引发错误

在当前的项目中,我正在进行大量试验,以了解不同解决方案的性能影响.由于我喜欢保留所有代码,因此我有很多#ifdef指令,这使我可以轻松地打开和关闭某些优化.但是,未涵盖某些定义组合.如果发生这种情况,我希望看到编译器错误,即:

#define A
#define B

#ifdef A
#ifdef B
//invalid combination of defines. Compiler should raise an error.
#endif
#endif

#ifdef A
//do something
#endif
#ifdef B
//do something else
#endif
Run Code Online (Sandbox Code Playgroud)

那可能吗?

c-preprocessor preprocessor-directive

1
推荐指数
1
解决办法
215
查看次数

预处理前的C/C++文件

是否可以在预处理之前查看ac/c ++文件?或者更确切地说,只是半心半意的预处理?基本上有一个

#define <commonly_used_word> 0
Run Code Online (Sandbox Code Playgroud)

在第三方库标题中,我想弄清楚它在哪里.所以基本上,我只是希望编译器包含所有头文件而不是预处理器.

c-preprocessor preprocessor-directive

1
推荐指数
1
解决办法
203
查看次数

为什么#if预处理器不起作用?

使用以下代码,当我打算获得"NOT VGA"时,我总是将"VGA"作为输出

#include<stdio.h>
#include<conio.h>
#define ADAPTER NVGA
#if ADAPTER==VGA
 int main()
 {
 printf("VGA");
 getch();
 return 0;
 }
#else
     int main()
 {
 printf(" NOT VGA");
 getch();
 return 0;
 }
 #endif
Run Code Online (Sandbox Code Playgroud)

c preprocessor-directive

1
推荐指数
1
解决办法
114
查看次数

C/C++两个宏的功能

我对自己的能力不如我应该这么好,所以我想也许我可以#define做点什么.

不幸的是,当谈到预处理程序指令时,我非常缺乏经验,我无法弄清楚如何处理循环等问题.我在看:

但他们都没有for循环的例子.我想要的只是能够写出类似的东西,pwrtwo(5)而不是使用计算器来弄清楚2 5是32.

c++ macros preprocessor-directive

1
推荐指数
2
解决办法
5813
查看次数

VS 2015 Community Edition中项目属性UI中的C/C++预处理器设置在哪里?

由于希望接受C++作为零新手的培训,我遵循指令在配备Windows 10和Visual Studio 2015 Community Edition的PC上创建C++开发环境.

我在VS 2015 CE上创建了一个新的C++项目 VS CE中的空C++项目

当我右键单击项目属性时,我无法找到C/C++>预处理器 - 从屏幕截图中可以看出它不存在.

在此输入图像描述

所以试图找出地球上的方法我可以在这里添加一些自定义预处理器定义.:-(

c++ preprocessor-directive visual-studio-2015 vs-community-edition

1
推荐指数
1
解决办法
1255
查看次数

#if使用枚举

我有一个头文件,如:

enum DataRate {
    AB0,
    AB1,
    AB2,
    ...
};
Run Code Online (Sandbox Code Playgroud)

在我的代码中我有类似的东西

#define S_FACTOR AB0
Run Code Online (Sandbox Code Playgroud)

现在,函数调用就像

foo(S_FACTOR);
Run Code Online (Sandbox Code Playgroud)

似乎工作正常,但有条件的编译

#if ( (S_FACTOR == AB0) || (S_FACTOR == AB2) )
Run Code Online (Sandbox Code Playgroud)

不能正常工作.

c enums if-statement c-preprocessor preprocessor-directive

1
推荐指数
1
解决办法
699
查看次数

在C99中的宏中使用true和false

我正在使用支持C99子集的自定义gcc编译器编写一些代码.使用编译器选项我定义了一个像这样的宏:

ENABLE_LOGGING=true
Run Code Online (Sandbox Code Playgroud)

我在我的代码中使用它,如下所示:

#if ENABLE_LOGGING
#define LOG(foo) { log(foo); }
#else
#define LOG(foo)
#endif
Run Code Online (Sandbox Code Playgroud)

事实证明,这不能可靠地运作.有时使用LOG包含代码,有时使用emtpy LOG(相同的项目,相同的编译器设置).

将宏参数更改为:

ENABLE_LOGGING=1
Run Code Online (Sandbox Code Playgroud)

一切正常.

据我所知,true预处理器可能不知道.但是,为什么它最常用?为什么在编译它不起作用的模块时,我没有得到任何警告或错误?

c boolean c99 c-preprocessor preprocessor-directive

1
推荐指数
1
解决办法
179
查看次数

在C#中的#if中使用#define预处理器指令是否有效?

我可以用#define 预处理指令#if#endif在C#中?

例如

#if !SILVERLIGHT && !__ANDROID__ && !__IOS__ 
#define SupportsMutex
#endif
Run Code Online (Sandbox Code Playgroud)

它看起来很有效,但我需要确定.有很多关于此的文章,但大部分时间都是在C语境中而不是C# - C#中的预处理程序指令a更加有限.

Visual Studio的突出显示似乎支持它,但根据语言/编译器规范它真的有效吗?

此MSDN页面提供了以下注意事项:

#define指令不能用于声明常量值,这通常在C和C++中完成.C#中的常量最好定义为类或结构的静态成员.如果你有几个这样的常量,可以考虑创建一个单独的"常量"类来保存它们.

我需要这个,因为#if !SILVERLIGHT && !__ANDROID__ && !__IOS__多次使用 很难管理.

当然,我们也可以添加项目SupportsMutex的"条件编译符号",但这更难管理,透明度更低.

c# conditional-compilation preprocessor-directive

1
推荐指数
1
解决办法
469
查看次数