这行在小型测试程序中正常工作,但在我想要它的程序中,我得到以下编译器投诉:
#include <limits>
x = std::numeric_limits<int>::max();
c:\...\x.cpp(192) : warning C4003: not enough actual parameters for macro 'max'
c:\...\x.cpp(192) : error C2589: '(' : illegal token on right side of '::'
c:\...\x.cpp(192) : error C2059: syntax error : '::'
Run Code Online (Sandbox Code Playgroud)
我得到了相同的结果:
#include <limits>
using namespace std;
x = numeric_limits<int>::max();
Run Code Online (Sandbox Code Playgroud)
为什么它将max视为宏max(a,b); ?
试图改进比较字符串的函数的性能我决定通过比较它们的哈希值来比较它们.那么,如果2个非常长的字符串的散列彼此相等,那么字符串也相互相等吗?
我有一个简单的递归函数RCompare(),它调用一个更复杂的函数Compare(),它在递归调用之前返回.每个递归级别使用248个字节的堆栈空间,这似乎比它应该的更多.这是递归函数:
void CMList::RCompare(MP n1) // RECURSIVE and Looping compare function
{
auto MP ne=n1->mf;
while(StkAvl() && Compare(n1=ne->mb))
RCompare(n1); // Recursive call !
}
Run Code Online (Sandbox Code Playgroud)
StkAvl()是一个简单的堆栈空间检查函数,它将自动变量的地址与存储在静态变量中的堆栈末尾附近的地址值进行比较.
在我看来,每次递归中唯一添加到堆栈的东西是两个指针变量(MP是指向结构的指针)和一个函数调用存储的东西,一些保存的寄存器,基本指针,返回地址等. ,所有32位(4字节)值.有没有办法是248字节呢?
我不知道如何在Visual Studio 2008中以有意义的方式实际查看堆栈.
谢谢
添加了反汇编:
CMList::RCompare:
0043E000 push ebp
0043E001 mov ebp,esp
0043E003 sub esp,0E4h
0043E009 push ebx
0043E00A push esi
0043E00B push edi
0043E00C push ecx
0043E00D lea edi,[ebp-0E4h]
0043E013 mov ecx,39h
0043E018 mov eax,0CCCCCCCCh
0043E01D rep stos dword ptr es:[edi]
0043E01F pop ecx
0043E020 mov dword ptr [ebp-8],edx
0043E023 mov dword ptr …Run Code Online (Sandbox Code Playgroud) 这对我来说很奇怪。有人可以解释为什么 activate() 函数需要时间戳吗?99.9% 的时间不是现在或尽快或“在您方便的时候”吗?此外,如果你尝试 w.activate(0) 你会收到这个警告:
Wnck-WARNING: Received a timestamp of 0; window activation may not function properly
Run Code Online (Sandbox Code Playgroud)
我读过的有关此警告的每个论坛帖子都没有答案。但它们似乎都表明代码无法正常工作,除非您实际输入时间戳。如果你输入 (0),事情就不起作用了,你会收到警告。但是,对我来说,如果我输入时间戳,那就是事情不起作用的时候。如果我使用 (0),则程序可以正常工作,但会收到警告(仅当我在终端窗口中运行它时)。
到底为什么 activate() 关心“时间”?
只有我觉得这很疯狂吗?
当我创建Combobox时,它没有列表中的项目.现在,当我点击下拉按钮时,会调用一个函数(通过postcommand选项),但是在我的函数中,我不知道如何在Combobox的列表框中设置值.
代码如下:
#update list upon drop down
self.cbox = Combobox(self, width = 10, postcommand = self.updtcblist)
def updtcblist(self):
list = self.getPortLst()
self.cbox.getlistbox.set(list) #getlistbox doesn't work
Run Code Online (Sandbox Code Playgroud)
谢谢,
哈维
如果我使用以下方法加载字体:
char *fName = (char *)"*-c-60-iso8859-1";
XFontStruct *font = XLoadQueryFont(disp, fName);
Run Code Online (Sandbox Code Playgroud)
它可以是与通配符名称匹配的几种字体中的任何一种。如何确定实际加载的全名?
[编辑] 更正了通配符名称以匹配多个:-c-是-m-哪个不匹配。[结尾]
是否有一种简单,干净的方法可以在编译时确定某些变量(此时是未知的)整数变量或类型的最大值和最小值?使用模板?
例如:
// Somewhere in a large project is:
typedef unsigned long XType;
typedef char YType;
// ...
// Somewhere else
XType a;
YType b;
LONGLONG c,d,e,f;
c = MinOfType(a); // Same as c = 0;
d = MaxOfType(a); // Same as d = 0xffffffff;
e = MinOfType(b); // Same as e = -128;
f = MaxOfType(b); // Same as f = 127;
// Also would be nice
e = MinOfType(YType); // Same as e = -128; // Using the …Run Code Online (Sandbox Code Playgroud) 由OP编辑.
我的计划需要进行大量的清理和重组.
在另一篇文章中,我询问了如何离开MFC DocView框架并转向WinProc和Message Loop方式(简称为什么?).那么目前我在想我应该清理Doc View中的内容,也许以后转换为非MFC甚至是有意义的.我的Document类目前几乎没有任何用处.
我认为一个开始的地方是InitInstance()函数(发布在下面).
在这部分:
POSITION pos=pDocTemplate->GetFirstDocPosition();
CLCWDoc *pDoc=(CLCWDoc *)pDocTemplate->GetNextDoc(pos);
ASSERT_VALID(pDoc);
POSITION vpos=pDoc->GetFirstViewPosition();
CChildView *pCV=(CChildView *)pDoc->GetNextView(vpos);
Run Code Online (Sandbox Code Playgroud)
这对我来说很奇怪.我只有一个文档和一个视图.我觉得我正在使用GetNextDoc()和GetNextView()向后推进它.尝试使用愚蠢的比喻; 这就像我手里拿着一本书,但我必须查看它的索引,找出书的标题所在的页面.我厌倦了对我的代码感到尴尬.我需要纠正或保证,或两者兼而有之.:)
此外,所有杂项都没有特别的顺序.我想将它们重新排列成可能更标准,更有条理或更直接的订单.
欢迎所有建议!
BOOL CLCWApp::InitInstance()
{
InitCommonControls();
if(!AfxOleInit())
return FALSE;
// Initialize the Toolbar dll. (Toolbar code by Nikolay Denisov.)
InitGuiLibDLL(); // NOTE: insert GuiLib.dll into the resource chain
SetRegistryKey(_T("Real Name Removed"));
// Register document templates
CSingleDocTemplate* pDocTemplate;
pDocTemplate = new CSingleDocTemplate(
IDR_MAINFRAME,
RUNTIME_CLASS(CLCWDoc),
RUNTIME_CLASS(CMainFrame),
RUNTIME_CLASS(CChildView));
AddDocTemplate(pDocTemplate);
// Parse command line for standard shell commands, DDE, file open
CCmdLineInfo cmdInfo; …Run Code Online (Sandbox Code Playgroud)