在Herb Sutter的书Exceptional C++(1999)中,他在第10项的解决方案中有词:
"异常不安全"和"糟糕的设计"齐头并进.如果一段代码不是异常安全的,那通常是可以的并且可以简单地修复.但是,如果一段代码由于其底层设计而不能被设置为异常安全,那几乎总是这是其设计不佳的信号.
示例1:具有两种不同职责的职能很难使例外安全.
示例2:以必须检查自我分配的方式编写的复制赋值运算符可能也不是强烈异常安全的
"检查自我分配"一词是什么意思?
[查询]
Dave和AndreyT向我们展示了"检查自我分配"的含义.非常好.但问题还没有结束.为什么"检查自我分配"会伤害"异常安全"(根据Hurb Sutter的说法)?如果调用者尝试进行自我分配,那么"检查"就像没有发生任何分配一样.真的疼吗?
[备忘1]在Herb的书后面的第38项对象身份中,他解释了自我分配.
我发现最佳做法是让所有文本文件都具有svn:eol-style=native属性集.但是最有效的方法是什么?
我主要在Windows上开发程序(使用TortoiseSVN和svn.exe命令行),有时为Windows和Linux编写可移植的C/C++库.为了防止我的源文件中令人讨厌的混合CR,LF问题,我认为svn:eol-style=native应该是"默认",但不幸的是它不是.
我从Subversion红皮书知道配置[auto-props]中~/.subversion/config或%APPDATA%\Subversion\config帮助,但是,它是每个客户端的设置.我团队中的某些开发人员忘记配置这些配置文件(考虑多个虚拟机上的dev)怎么样?即使所有人都记得,如果出现一些新的文本文件扩展名怎么办?如何将此更改正确地传播到我团队中所有dev计算机上的所有配置文件?
一切似乎都是一个繁琐的过程.
我知道ANSI C定义了fopen,fwrite,fread,fclose来修改文件的内容.但是,在截断文件时,我们必须转向操作系统特定的功能,例如,truncate()在Linux上,_chsize_s_()在Windows上.但在我们调用那些特定于操作系统的函数之前,我们必须通过调用来获取FILE指针的文件句柄fileno,也可以是非ANSI-C函数.
我的问题是:FILE*截断文件后继续使用是否可靠?我的意思是,ANSI C FILE层有自己的缓冲区,不知道文件是从下面截断的.如果缓冲的字节超出截断点,缓冲的内容是否会在执行时刷新到文件fclose()?
如果不能保证,在编写Windows-Linux可移植程序时,使用文件I/O函数以及截断操作的最佳做法是什么?
类似的问题:当从文件句柄返回时查询文件大小fileno时,我以后调用时是否准确大小fclose()- 没有进一步的fwrite()?
[编辑2012-12-11]
根据约书亚的建议.我得出结论,当前可能的最佳实践是:通过调用将流设置为无缓冲模式setbuf(stream, NULL);,然后truncate()或者_chsize_s()可以与流和平地工作.
无论如何,没有官方文档似乎明确证实了这种行为,无论是Microsoft CRT还是GNU glibc.
Process Explorer有时会将EXE显示为"打包图像",但它的含义是什么.
我发现的是:编译一个exe(使用Visual C++ 2010),/ZI选项结果是打包图像,但/Zi没有.为何如此差异?
BTW:编译的DLL /ZI也被认为是"打包图像"并标记为紫色.
我在Windows 7上有一个who.bat,
@echo off
REM This bat searches a file in PATH list to see whether a file can be found.
REM If found, it shows the file's full path.
REM which.bat gcc.exe
REM shows
REM gcc.exe is found: D:\GMU\MinGW2\bin\gcc.exe
REM
REM Note: Filename extension is significant in the search. E.g. If you run
REM which.bat gcc
REM gcc.exe will not be matched.
IF "%1" == "" goto END
IF "%~$PATH:1" == "" (
echo %1 is not found in …Run Code Online (Sandbox Code Playgroud) 我正在尝试使用Javascript代码美化,然后提出一个问题.
如果我不分配class="prettyprint"给<pre>在静态html,但希望以后应用prettyprint(例如,当用户点击一个"彩色化"在我的网页按钮),我怎么能做到这一点?
略微修改原始的run_prettify.js或prettify.js是可以接受的,因为我将把它用于离线使用.
我的实验:
编写try-delay-class.html:
<html>
<head>
<script src="https://google-code-prettify.googlecode.com/svn/loader/run_prettify.js"></script>
</head>
See it:
<pre>
class Voila {
public:
// Voila
static const string VOILA = "Voila";
// will not interfere with embedded <a href="#voila1">tags</a>.
}
</pre>
</html>
Run Code Online (Sandbox Code Playgroud)
在Chrome v26中打开,调出控制台,执行:
pres=document.getElementsByTagName('pre')
pres[0].className+=" prettyprint"
Run Code Online (Sandbox Code Playgroud)
语法颜色没有出现.

在带有IE8的Windows 7上,我发现display: inline-block效果很好.但是,在我将html文件编译成chm后,chm中的页面显示效果不佳,好像inline-block没有任何效果.
有没有办法让chm显示与IE8相同?谢谢.

我的html源代码是:
<!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd">
<html>
<head>
<title>title to fill</title>
<meta charset="utf-8">
<style type="text/css">
#topcanvas {
z-index: 0;
top: 0;
left:0;
width:100%;
}
#chjnavi {
font-size: 10pt;
background-color: #eee;
padding: 0em 1em;
list-style-type: none;
position: relative;
z-index: 0;
}
#chjnavi ul {
margin: 0;
padding: 0;
}
#chjnavi li {
margin: 0;
padding: 8px;
display: inline-block;
/* !!! */
cursor: pointer;
}
</style>
</head>
<div id="topcanvas">
<div id="chjnavi"> …Run Code Online (Sandbox Code Playgroud) 我有这样的WiX代码:
<DirectoryRef Id="MyShortcutsDir">
<Component Id="CMP_StartMenuShortcuts" Guid="62A9F5D2-F9D9-4F9B-8382-D470E11B2332">
<Shortcut Id="docEng" Name="UFCOM user guide - ENG (pdf)" Target="[INSTALLFOLDER]UFCOM user guide - ENG.pdf" />
<Shortcut Id="docChs" Name="UFCOM user guide - CHS (pdf)" Target="[INSTALLFOLDER]UFCOM user guide - CHS.pdf" />
<Shortcut Id="UninstallShortcut" Name="Uninstall [ProductName] ~ [ProductVersion]" Target="[System64Folder]msiexec.exe" Arguments="/x [ProductCode]" Description="Remove UFCOM from your Windows" />
<RemoveFolder Id="RemoveMyShortcutsDir" On="uninstall" />
<RegistryValue Root="HKCU" Key="Software\Newland Auto-ID\UFCOM" Name="installed" Type="integer" Value="1" KeyPath="yes" />
<!-- On Win7, these shortcuts(.lnk) resides in "C:\ProgramData\Microsoft\Windows\Start Menu\Programs\UFCOM" -->
</Component>
</DirectoryRef>
Run Code Online (Sandbox Code Playgroud)
但是我发现[ProductCode]可以在[ProductName]不能的时候出现,为什么会这样呢?那么如何在元素中引用产品名称定义?
<Product Id="*" Name="UFCOM Driver 1.3.6" …Run Code Online (Sandbox Code Playgroud) Python 有一个unicode内置函数可以将字节流转换为 unicode 字符串。

我只是希望我可以查询我的系统上所有可用的编码。但如何。
这个问题的原因是:有人使用 MAC OS X 向我发送了一封内容编码为“iso-2022-cn”的电子邮件,我发现 Windows 7 上的 Python 2.7 无法识别该编码。
>>> print unicode(bs2022, 'iso-2022-cn')
Traceback (most recent call last):
File "<pyshell#97>", line 1, in <module>
print unicode(bs2022, 'iso-2022-cn')
LookupError: unknown encoding: iso-2022-cn
Run Code Online (Sandbox Code Playgroud)
所以我想通过查看Python可以支持的所有编码来找出Python是否对“iso-2022-cn”使用了不同的名称。
在 Ubuntu Linux 20.04 机器上,在 中/usr/include/x86_64-linux-gnu/bits/resource.h,我看到如下代码:
enum __rusage_who
{
/* The calling process. */
RUSAGE_SELF = 0,
#define RUSAGE_SELF RUSAGE_SELF
/* All of its terminated child processes. */
RUSAGE_CHILDREN = -1
#define RUSAGE_CHILDREN RUSAGE_CHILDREN
};
Run Code Online (Sandbox Code Playgroud)
我们看到它RUSAGE_SELF被定义为它本身。其目的/好处是什么?
c ×2
c++ ×2
windows ×2
batch-file ×1
chm ×1
cmd ×1
css ×1
file-io ×1
javascript ×1
pretty-print ×1
process ×1
python ×1
svn ×1
wix ×1