拿这个玩具代码:
#include <iostream>
#include <fstream>
int main() {
std::ifstream is;
// perform read
// ...
if (!is) // works
std::cout << "fail";
if( is == false) // error C2678
std::cout << "fail";
return 0;
}
Run Code Online (Sandbox Code Playgroud)
你会得到以下反直觉的结果:if(!is)编译,并if(is==false)给出
错误C2678:二进制'==':找不到哪个运算符带有'std :: ifstream'类型的左操作数(或者没有可接受的转换)
(对于VS2015 - gcc和clang中的类似错误).
标准说(根据这个答案):
依赖于隐式布尔转换的有效C++ 2003代码将无法使用此国际标准进行编译.此类转换发生在以下条件中:
将值传递给带有bool类型参数的函数;
使用operator ==来比较false或true;
从返回类型为bool的函数返回一个值;
通过聚合初始化初始化bool类型的成员;
初始化一个const bool&将绑定到一个临时的.
据我所知if(is==false),明确要求失败,但怎么if(!is)没有?它不符合"隐式布尔转换"的条件吗?
这个转换为bool是否故意从标准中列出的案例中删除?也许这是一个无意的遗漏?
编辑:此代码也失败了:
int main() {
std::ifstream is;
// perform read
// ...
if (is) // works
std::cout …Run Code Online (Sandbox Code Playgroud) PLT 使用方式在 SystemV ABI 中指定(并在实践中实现),示意性如下:
# A call from somewhere in code is into a PLT slot
# (In reality not a direct call, in x64 typically an rip-relative one)
0x500:
call 0x1000
...
0x1000:
.PLT1: jmp [0x2000] # the slot for f in the binary's GOT
pushq $index_f
jmp .PLT0
...
0x2000:
# initially jumps back to .PLT to call the lazy-binding routine:
.GOT1: 0x1005
# but after that is called:
0x3000 # the address of the real implementation …Run Code Online (Sandbox Code Playgroud) 在发布版本中链接我的dll时,我得到 -
1> LINK:警告LNK4098:defaultlib'mfc80d.lib'与使用其他库冲突; 使用/ NODEFAULTLIB:库
1> LINK:警告LNK4098:defaultlib'mfcs80d.lib'与使用其他库冲突; 使用/ NODEFAULTLIB:库
1> LINK:警告LNK4098:defaultlib'msvcrtd.lib'与使用其他库冲突; 使用/ NODEFAULTLIB:库
添加/ VERBOSE,我看到以下(片段):...
1>搜索D:\ Microsoft Visual Studio 8\VC\atlmfc\lib\mfc80d.lib:
1>找到"public:virtual __thiscall AFX_MODULE_STATE :: ~AFX_MODULE_STATE(void)"(?? 1AFX_MODULE_STATE @@ UAE @ XZ)1>
在mfcs80.lib(dllmodul.obj)中引用1>已加载mfc80d.lib(MFC80D.DLL)1>找到"long stdcall AfxWndProc(struct HWND __,unsigned int,unsigned int,long)"(?AfxWndProc @@ YGJPAUHWND __ @@ IIJ @ Z)
1>在mfcs80.lib(dllmodul.obj)中引用1>已加载mfc80d.lib(MFC80D.DLL)
...
如果我正确地解释这个,这意味着链接器以某种方式解析来自(优化的)库mfcs80的调用,作为对(非优化的)库mfc80D的调用.怎么会这样??
当我添加/NODEFAULTLIB:mfc80d.lib时,警告消失了,但我还没有安静下来.顺便说一下,该模块确实遭受了增量链接上偶然发生的莫名其妙的崩溃,这只能通过重新构建来解决.我正在使用VS2005.
[编辑:]将标题更改为包含DEFAULTLIB,希望更好地聚焦主题.我确实看到一条明确的说法
已处理/DEFAULTLIB:mfc80d.lib
在/ VERBOSE输出中,以及许多其他(非调试)默认库.它从何而来?我怎样才能解决这个问题?
谢谢!
VC++中一个非常特殊的代码序列生成了以下指令(对于Win32):
unpcklpd xmm0,xmmword ptr [ebp-40h]
Run Code Online (Sandbox Code Playgroud)
出现2个问题:
(1)据我了解intel手册,unpcklpd接受128对齐的内存地址作为第二个参数.如果地址相对于堆栈帧,则不能强制对齐.这真的是一个编译器错误吗?
(2)只有在从调试器运行时才会执行此指令时抛出异常,即使这样也不总是如此.即使附加到进程并执行此代码也不会抛出.怎么会这样??
抛出的特殊异常是0xFFFFFFFF处的访问冲突,但是AFAIK只是一个未对齐的代码.
[编辑:]这里有一些来源证明代码生成错误 - 但通常不会导致崩溃.(这主要是我想知道的)
[编辑2:]代码示例现在重现实际崩溃.这个也在调试器外崩溃 - 我怀疑是因为调试器在不同的典型基地址启动程序而产生差异.
// mock.cpp
#include <stdio.h>
struct mockVect2d
{
double x, y;
mockVect2d() {}
mockVect2d(double a, double b) : x(a), y(b) {}
mockVect2d operator + (const mockVect2d& u) {
return mockVect2d(x + u.x, y + u.y);
}
};
struct MockPoly
{
MockPoly() {}
mockVect2d* m_Vrts;
double m_Area;
int m_Convex;
bool m_ParClear;
void ClearPar() { m_Area = -1.; m_Convex = 0; m_ParClear = true; …Run Code Online (Sandbox Code Playgroud) 我有一个混合的托管/本机桌面解决方案.开始调试时,需要大约一分钟(!)才能启动,并立即进入调试对象.
几个信息:
1)在主线程上打破'立即'=在此堆栈上的中断:
> kernel32.dll!GetFullPathNameW() Unknown
mscorlib.ni.dll!00007ffaa4f51310() Unknown
[Managed to Native Transition]
mscorlib.dll!System.IO.PathHelper.GetFullPathName() Unknown
mscorlib.dll!System.IO.Path.NormalizePath(string path = "D:\\cwx_tfs\\718_High_risk_branch\\Application\\Bin\\Debug\\CathWorksUI.exe.Config", bool fullCheck, int maxPathLength = 260, bool expandShortPaths = true) Unknown
mscorlib.dll!System.IO.Path.GetFullPathInternal(string path) Unknown
mscorlib.dll!System.AppDomainSetup.NormalizePath(string path, bool useAppBase) Unknown
mscorlib.dll!System.AppDomainSetup.VerifyDir(string dir, bool normalize) Unknown
System.Configuration.dll!System.Configuration.ClientConfigPaths.ClientConfigPaths(string exePath = null, bool includeUserConfig) Unknown
System.Configuration.dll!System.Configuration.ClientConfigPaths.GetPaths(string exePath, bool includeUserConfig = false) Unknown
System.Configuration.dll!System.Configuration.ClientConfigurationHost.GetStreamName(string configPath) Unknown
System.Configuration.dll!System.Configuration.ClientConfigurationHost.IsAppConfigHttp.get() Unknown
System.Configuration.dll!System.Configuration.ClientConfigurationSystem.ClientConfigurationSystem() Unknown
System.Configuration.dll!System.Configuration.ConfigurationManager.EnsureConfigurationSystem() Unknown
System.Configuration.dll!System.Configuration.ConfigurationManager.PrepareConfigSystem() Unknown
System.Configuration.dll!System.Configuration.ConfigurationManager.GetSection(string sectionName = "system.diagnostics") Unknown
System.dll!System.Configuration.PrivilegedConfigurationManager.GetSection(string sectionName) Unknown
System.dll!System.Diagnostics.DiagnosticsConfiguration.Initialize() Unknown
System.dll!System.Diagnostics.DiagnosticsConfiguration.Sources.get() Unknown
System.dll!System.Diagnostics.TraceSource.Initialize() …Run Code Online (Sandbox Code Playgroud) data.table 的:=操作符记录为:
... 通过引用添加或更新或删除列。它根本不复制内存的任何部分。
那么这里会发生什么呢?
dt <- data.table(a = 1:5, b = 6:10)
address(dt$b)
# [1] "0000021cca78db58"
dt[, b := 2*a]
address(dt$b)
# [1] "0000021cc77ade10"
Run Code Online (Sandbox Code Playgroud)
b列地址怎么变了?
我正在使用 R 3.6.1 和 data.table 1.12.8。
我编译了以下代码-Wsign-conversion:
int main()
{
unsigned int a = 8;
int b = a + 8u; // warning: implicit conversion changes signedness: 'unsigned int' to 'int'
int c = a - 8u; // warning: implicit conversion changes signedness: 'unsigned int' to 'int'
int d = a * 8u; // warning: implicit conversion changes signedness: 'unsigned int' to 'int'
int e = a / 8u; // gcc warns, but no warning in clang
}
Run Code Online (Sandbox Code Playgroud)
从无符号除法的结果进行分配时,Clang 不会发出警告,但 gcc 会发出警告。
为什么在这种特殊情况下会有所不同?
这不是这个的重复,也不是我在 SO(和外部)上找到的任何其他内容。
我从另一个存储库(我们称之为“上游”)创建了一个 github 分支(假设是“起源”)。时间过去了,我希望上游的起源发生变化。今天,github 有一个漂亮的“获取上游”按钮,可以更新我创建原始分支时存在的分支,并且单独更新它们。
github文档列出了据称相当于“获取上游”UI 的命令:
$ git fetch upstream
...
$ git checkout main
...
$ git merge upstream/main
Run Code Online (Sandbox Code Playgroud)
那么“获取上游”UI 不会尝试更新非默认分支?更不用说创造新的了?
通过命令行实现此目的的正确方法是什么?(我将原点和上游设置为遥控器,并做了一个fetch --all)
有没有地方可以让我们和 github 开发者自己讨论这个问题?我找不到合适的仓库(他们有 400 多个)。在我看来,这是一个有价值的潜在改进。
检查这个玩具代码:
> x <- data.table(a = 1:2)
> foo <- function(z) { z[, b:=3:4] }
> y <- foo(x)
> x[]
a b
1: 1 3
2: 2 4
Run Code Online (Sandbox Code Playgroud)
看来 data.table 是通过引用传递的。这是故意的吗?这有记录吗?我确实阅读了文档,但找不到提及此行为。
我并不是在询问 R 的文档化参考语义(在:=以及set***其他一些文档中)。我问 data.table 完整对象是否应该作为函数参数通过引用传递。
编辑:根据@Oliver 的回答,这里有一些更奇怪的例子。
> dt<- data.table(a=1:2)
> attr(dt, ".internal.selfref")
<pointer: 0x564776a93e88>
> address(dt)
[1] "0x5647bc0f6c50"
>
> ff<-function(x) { x[, b:=3:4]; print(address(x)); print(attr(dt, ".internal.selfref")) }
> ff(dt)
[1] "0x5647bc0f6c50"
<pointer: 0x564776a93e88>
Run Code Online (Sandbox Code Playgroud)
因此,不仅.internal.selfref与调用者的 dt 副本相同,而且地址也相同。这确实是同一个物体。(我认为)。 …