最近,我一直在处理一些同事的一些遗留代码,使用 Visual Studio 代码我已经能够将其转换为清晰且可读的 C 格式。然而,我想折叠一些控制语句,因为我的同事编写的控制语句有时会超过 100 行。
在这些行中,我添加了预处理器控制语句来启用和禁用我的更改。
在 Visual Studio 代码中,我能够很好地折叠代码,但是一旦遇到预处理器语句(至少是 #ifdef 和 #ifndef),它就会停止。由于大约每 10 行中有 1 行要折叠一个控制语句,我需要折叠 10 次,这有点打败了它背后的想法,对吗?
我尝试在设置和一些谷歌搜索中寻找折叠和折叠,但我找不到任何可以解决我的问题的东西。
例如我有这个片段
if(true)
{
Some functions();
#ifdef DEBUG
Functions with debugging only();
#else
Functions without debugging only();
#endif
Some other functions();
}
Run Code Online (Sandbox Code Playgroud)
我希望,每当我折叠 if(true) 时,该控制语句中的所有内容都会被折叠。这是我习惯的,也是在 Eclipse 中 vs2017 中会发生的情况。这在 VSCODE 中不会发生!而只是一些函数();被折叠。
如何使 VSCODE 折叠行为与其他 IDE 类似?
因此,我有一个 DataFrame,其中包含当前12345按行排列的分类值和数值值171。
我在分类变量和数值变量中都缺少值,我想在其中估算值。对于数字列,我正在执行以下操作;
import pandas as pd
import numpy as np
data = pd.read_csv('filepath')
from sklearn.preprocessing import Imputer
imp = Imputer(missing_values=np.nan, strategy='mean', axis=0)
data = imp.fit_transform(data)
Run Code Online (Sandbox Code Playgroud)
然后我收到以下错误
ValueError:无法将字符串转换为浮点数:'USD'
我理解这是因为我使用的 sci-kit learns imputer 与strategy='mean'分类变量不兼容。我宁愿不必遍历每一列并手动提取数值,因此我正在寻找一种只能在数值列上执行此插补的方法。
我必须在 .S 文件中包含 .h 中的一些宏。.h 还包含 c 声明。因此我使用了定义
gcc -E -dM header.h > generated_header.h
generated_header.h还具有所有预定义的宏和标准符号。
现在 gcc -Iinclude/ asm.S -o asm.o 给出以下警告的数量
warning: "__GCC_ATOMIC_LLONG_LOCK_FREE" redefined
warning: "__GCC_ATOMIC_SHORT_LOCK_FREE" redefined
warning: "__STDC__" redefined ETC...
这是因为我们通过在asm.S中包含generated_header.h再次重新定义相同的宏
我检查了所有预处理器选项以仅提取本地定义。但没有任何帮助。有没有其他方法可以解决这个问题。有没有其他方法可以让 asm.S 知道这些宏?
C++ 知道assert()哪个允许运行时检查,根据NDEBUG.
我想使用编译器代码替换该宏并避免使用预处理器。我需要执行以下操作:
falseNDEBUG放弃构建的检查和传递的表达式中断/终止应用程序很容易。
在 C++20 中,std::experimental::source_location我可以使用它来获取断言的代码位置。
编译时条件可以使用requires或完成constexpr if
但是我不知道如何避免对表达式的求值。当myAssert(expression)作为函数实现时,我需要将表达式结果作为函数参数传递,这意味着即使该参数未在函数内部使用,它仍然会被计算。
C++20 有没有办法解决这个问题?
编辑:模板化示例:
template <typename T> requires (gDebug)
void assertTrue(const T& pResult, const std::experimental::source_location& pLocation) noexcept
{
if (!static_cast<bool>(pResult))
{
// error handling
}
}
template <typename T> requires (!gDebug)
void assertTrue(const T&) noexcept
{
}
Run Code Online (Sandbox Code Playgroud) 我看到很多建议使用 re (正则表达式)或 python 中的 .join 删除句子中连续重复的字母,但我想对特殊单词有例外。
例如:
我想要这句话>sentence = 'hello, join this meeting heere using thiis lllink'
像这样>'hello, join this meeting here using this link'
知道我有这个单词列表要保留并忽略重复的字母检查:keepWord = ['Hello','meeting']
我发现有用的两个脚本是:
使用.join:
import itertools
sentence = ''.join(c[0] for c in itertools.groupby(sentence))
Run Code Online (Sandbox Code Playgroud)
使用正则表达式:
import re
sentence = re.compile(r'(.)\1{1,}').sub(r'\1', sentence)
Run Code Online (Sandbox Code Playgroud)
我有一个解决方案,但我认为还有一个更紧凑、更高效的解决方案。我现在的解决方案是:
import itertools
sentence = 'hello, join this meeting heere using thiis lllink'
keepWord = ['hello','meeting']
new_sentence = ''
for word in sentence.split():
if word not in keepWord:
new_word = …Run Code Online (Sandbox Code Playgroud) 当我将XCode 4中的预处理器宏添加到我的一个目标时,它会被使用,并且按照我的预期进行条件编译.
但是,如果我将该设置移动到项目级别并从我的一个目标中移出,则预处理器宏显然会被忽略而根本不会被使用.
我确认,如果我通过仅在启用该宏时编译的日志记录将其放入项目的构建设置中,则根本定义宏.
怎么可能?
系统:OS X Lion,XCode 4.1 build 4B110,用于iOS 4.3.5,使用LLVM编译器,而不是GCC.
我试图弄清楚为什么以下GLSL代码不起作用:
#ifndef VertexPositionType
#define VertexPositionType vec3
#endif
in StandardVertexShaderInputs {
VertexPositionType ds_VertexPosition;
};
vec4 ProjectVertexPosition(in vec4 v);
vec4 ProjectVertexPosition(in vec3 v);
void main() {
gl_Position = ProjectVertexPosition(ds_VertexPosition);
}
Run Code Online (Sandbox Code Playgroud)
着色器拒绝编译.信息日志状态:
错误C1008:未定义变量"ProjectVertexPosition"
即使它没有警告预处理器,我得到的是预处理器符号VertexPositionType没有被替换.如果我删除预处理器定义,一切都很好.
现在,规范说:
#define和#undef功能被定义为具有和不具有宏参数的宏定义的C++预处理器的标准.
也许以下行不是有效的预处理器行?
#define VertexPositionType vec3
Run Code Online (Sandbox Code Playgroud) 你能告诉我怎样才能做到以下几点:
#if __unix__
#define path_sep='/'
#elif __windows__
#define path_sep='\'
#else
#error "path_sep not defined."
#endif
Run Code Online (Sandbox Code Playgroud)
使用gfortran编译器.
如何在我同时定义两个指令时,我会得到编译错误?我想要错误
#define ENG
#define POL
#if defined POL
#if defined ENG
Run Code Online (Sandbox Code Playgroud)
这不是
#define ENG
//#define POL
#if defined POL
#if defined ENG
Run Code Online (Sandbox Code Playgroud) 我正在构建一个在其中一个方法中使用preprocesor标志的框架.类似下面的代码:
public func heyStuck(overflow: String) {
#if DEBUG
print(overflow)
#else
print("¯\\_(?)_//¯")
#endif
}
Run Code Online (Sandbox Code Playgroud)
关键是我使用Cocoapods导入我的框架,所以为了定义框架的标志DEBUG,我必须在我的App Podfile中做这样的事情:
post_install do |installer_representation|
installer_representation.pods_project.targets.each do |target|
target.build_configurations.each do |config|
if config.name != 'Release'
config.build_settings['GCC_PREPROCESSOR_DEFINITIONS'] ||= ['$(inherited)', 'DEBUG=1']
end
end
end
end
Run Code Online (Sandbox Code Playgroud)
有没有办法将这些信息添加到podspec文件,以避免应用程序在他们的Podfile上定义这个东西?