我正在使用必须与各种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和谷歌.
我想知道是否有一种标准方法可以将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)
谢谢
我有一个 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指令中扩展预处理器变量?
我知道我可以使用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)
换句话说,我想使用预处理器来检查特定宏定义的值.当我尝试它时,这不起作用.
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: …
我试图根据编译时环境使一些F#代码有条件,并且找不到F#编译器可识别的任何特定于操作系统的定义.#if MONO不起作用.有没有办法在F#的编译时检测操作系统?
我有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) 我正在查看一些代码,发现它在调用函数时使用 \ 来分隔行,这是否意味着什么?还是只是为了更具可读性?
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) 考虑一下我写的这个简短的程序:
#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,并且我正在使用 …
确保仅定义两个名称之一的最简单方法是什么,例如:
#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) preprocessor ×10
c ×4
macros ×4
c++ ×2
algorithm ×1
assembly ×1
compilation ×1
f# ×1
fortran ×1
gcc ×1
include ×1
inno-setup ×1
intel ×1
line-numbers ×1
mono ×1
postscript ×1