标签: preprocessor

什么是区分ifort与其他fortran编译器的宏?

我正在使用必须与各种Fortran编译器一起工作的Fortran代码(并且与C++和Java代码交互).目前,我们正在使用gfortran和g95,但是我正在研究如何使用ifort,并且我遇到的第一个问题是如何确定如何在源代码中确定它是使用ifort还是不.

例如,我目前有这段代码:

#if defined(__GFORTRAN__)
// Macro to add name-mangling bits to fortran symbols. Currently for gfortran only
#define MODFUNCNAME(mod,fname) __ ## mod ## _MOD_ ## fname
#else
// Macro to add name-mangling bits to fortran symbols. Currently for g95 only
#define MODFUNCNAME(mod,fname) mod ## _MP_ ## fname
#endif // if __GFORTRAN__
Run Code Online (Sandbox Code Playgroud)

ifort的宏是什么?我尝试过IFORT,但这不对,进一步的猜测似乎没有效果.我也尝试阅读手册页,使用ifort -help和谷歌.

preprocessor fortran intel

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

将一个 postscript 文件包含到另一个文件中?

我想知道是否有一种标准方法可以将postscript文件包含到另一个文件中。例如,假设我有一个由第三方程序生成的数据文件:

%!PS
\mydata [ 1 2 3 4 5 6       
(...)
1098098
1098099
] def
Run Code Online (Sandbox Code Playgroud)

我想将它包含到主要的 PS 文档中

%PS
\processData
{
mydata { (..) } foreach
}

(...)

(data.ps) include %<=== ???
Run Code Online (Sandbox Code Playgroud)

谢谢

preprocessor postscript include

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

Inno Setup:如何在#error 指令消息中扩展预处理器变量

我有一个 Inno Setup 脚本,它查找文件作为预处理器步骤:

#define a_path GetEnv("INSTALLER_FILES")
#define install_file FindFirst(a_path + "\pattern*.*")
Run Code Online (Sandbox Code Playgroud)

install_file找不到时,我想发出一个错误:

#if install_file == 0
    #error No installer found at {#a_path}
#endif
Run Code Online (Sandbox Code Playgroud)

但是 ISPP 只在编译时写入文字源代码行:

script.iss: [ISPP] 在 {#a_path} 找不到安装程序

是否可以在#error指令中扩展预处理器变量?

preprocessor inno-setup

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

我可以使用C预处理器有条件地检查宏的值吗?

我知道我可以使用C预处理器有条件地编译类似的东西:

#define USESPECIALFEATURE

#if defined USESPECIALFEATURE
usespecialfeature();
#endif
Run Code Online (Sandbox Code Playgroud)

但我想知道我是否可以这样做:

#define USEDFEATURE 4

#if defined USEDFEATURE == 4
usefeature(4);
#endif
Run Code Online (Sandbox Code Playgroud)

换句话说,我想使用预处理器来检查特定宏定义的值.当我尝试它时,这不起作用.

c macros preprocessor

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

For-loop macro/preprocessor for assembly files in GCC

I am fairly certain I have seen this in code before, but I am unable to find any references on how to do it. I do expect this to be compiler or assembler specific.

I want to define an function pointer array of (compile-time) fixed length for use as an interrupt vector table on an embedded device. Each handler will push its interrupt number before jumping to a common handler. Creating a macro for these simpler functions is straight forward: …

macros assembly gcc preprocessor

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

如何检测在Mono上编译F#程序?

我试图根据编译时环境使一些F#代码有条件,并且找不到F#编译器可识别的任何特定于操作系统的定义.#if MONO不起作用.有没有办法在F#的编译时检测操作系统?

mono f# preprocessor compilation

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

在C语言的编译时找到100个结构的最大大小

我有100个结构,看起来像这样:

struct s00 { char   data[30]; };
struct s01 { char   data[30]; };
struct s02 { int    data[10]; };
struct s03 { double data[5];  };
struct s04 { float  data[20]; };
struct s05 { short  data[15]; };
struct s06 { char   data[7];  };
struct s07 { int    data[19]; };
struct s08 { double data[11]; };
struct s09 { float  data[5];  };
struct s10 { char   data[52]; };
//...
struct s99 { char   data[12]; };

typedef struct s00 s00;
typedef struct …
Run Code Online (Sandbox Code Playgroud)

c algorithm macros preprocessor

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

在 C 中调用函数时 \ 是什么意思?

我正在查看一些代码,发现它在调用函数时使用 \ 来分隔行,这是否意味着什么?还是只是为了更具可读性?

        function(\
        lets_say_this_a_long_attribute, \
        and_this_is_another_attribute_with_a_long_name_or_operations, \
        attribute);
Run Code Online (Sandbox Code Playgroud)

c preprocessor preprocessor-directive

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

如何使用 __LINE__ 或其他方法从呼叫站点获取行号?

考虑一下我写的这个简短的程序:

    #include <iostream>
    
    template<bool Debug = false>
    constexpr int add(const int& a, const int& b) { 
        if (Debug)
            std::cout << __FUNCTION__ << " called on line " << __LINE__ << '\n';
        return (a + b);
    }
    
    int main() {
        std::cout << add(3, 7) << '\n';
        std::cout << add<true>(5, 9) << '\n';
        return 0;
    }
Run Code Online (Sandbox Code Playgroud)

它工作得很好,并且提供了正确的输出:

10
add called on line 6
14
Run Code Online (Sandbox Code Playgroud)

但是,我希望打印的行号是程序调用站点上的行,在该程序中应该是第 12 行。

那么我如何使用__LINE__或其他一些方法来给我调用函数的行号?

所需的输出是:

10
add called on line 12
14
Run Code Online (Sandbox Code Playgroud)

如果可能,我希望它从函数本身生成。


-编辑-

作为对读者的说明,我对任何和所有选项都持开放态度,但对于我当前的构建环境,我仅限于 C++17,并且我正在使用 …

c++ macros preprocessor line-numbers visual-studio-2017

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

你如何在 C 预处理器中使用定义进行逻辑异或异或

确保仅定义两个名称之一的最简单方法是什么,例如:

#define USE_OPTION1
#define USE_OPTION2

#if not(USE_OPTION1 ^ USE_OPTION2)
#error "You must use at least one option, but not both"
#endif
Run Code Online (Sandbox Code Playgroud)

我知道 C 或 C++ 中没有逻辑异或,那么最好的方法是什么?不一定是这样,是吗:

#define USE_OPTION1
#define USE_OPTION2
        
#ifdef USE_OPTION1
  #ifdef USE_OPTION2
  #error "You can't use both"
  #endif
#endif

#ifdef USE_OPTION2
  #ifdef USE_OPTION1
  #error "You can't use both"
  #endif
#endif

#ifndef USE_OPTION1
  #ifndef USE_OPTION2
  #error "You must use at least one"
  #endif
#endif
Run Code Online (Sandbox Code Playgroud)

c c++ preprocessor

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