我编写了以下示例程序,但它与segfault崩溃.问题似乎是在结构中使用malloc和std::strings.
#include <iostream>
#include <string>
#include <cstdlib>
struct example {
std::string data;
};
int main() {
example *ex = (example *)malloc(sizeof(*ex));
ex->data = "hello world";
std::cout << ex->data << std::endl;
}
Run Code Online (Sandbox Code Playgroud)
我无法弄清楚如何让它发挥作用.任何想法,如果它甚至可以使用malloc()和std::strings?
谢谢,Boda Cydo.
我需要在字符串中匹配冒号(':'),但不能用引号括起来 - 或者是"或"字符.
所以以下应该有2场比赛
something:'firstValue':'secondValue'
something:"firstValue":'secondValue'
Run Code Online (Sandbox Code Playgroud)
但这应该只有1场比赛
something:'no:match'
Run Code Online (Sandbox Code Playgroud) 在32位系统上.
std::vector<char>::max_size()返回2 32 -1,大小为char-1字节std::vector<int>::max_size()返回2 30 -1,大小为int-4字节std::vector<double>::max_size()返回2 29 -1,大小为double- 8字节任何人都可以告诉我max_size()取决于什么?
max_size()如果它在64位系统上运行,它的返回值是多少?
当试图在Emacs中运行Mx Flymake-Mode时,我得到:
Flymake: Configuration error has occured while running (make -s -C ./CHK_SOURCES=helloworld_flymake.c SYNTAX_CHECK_MODE=1 check-syntax). Flymake will be switched OFF
Run Code Online (Sandbox Code Playgroud)
我在一个名为helloworld.c的缓冲区中调用该命令:
#include <stdio.h>
int main(void) {
printf("Hello World");
return 0;
}
Run Code Online (Sandbox Code Playgroud)
并在同一目录中有一个名为Makefile的文件:
helloworld: helloworld.c
gcc helloworld.c -o helloworld
Run Code Online (Sandbox Code Playgroud)
我在Ubuntu 9.04下运行GNU Emacs 23.0.91.1.
提前致谢!
是否有一个函数(SSEx内在函数可以),它将用指定的int32_t值填充内存?例如,当此值等于0xAABBCC00结果时,内存应如下所示:
AABBCC00AABBCC00AABBCC00AABBCC00AABBCC00
AABBCC00AABBCC00AABBCC00AABBCC00AABBCC00
AABBCC00AABBCC00AABBCC00AABBCC00AABBCC00
AABBCC00AABBCC00AABBCC00AABBCC00AABBCC00
...
Run Code Online (Sandbox Code Playgroud)
我可以使用std::fill或简单的for循环,但它不够快.
在程序开始时仅调整一次矢量的大小,这不是问题.瓶颈正在填补记忆.
简化代码:
struct X
{
typedef std::vector<int32_t> int_vec_t;
int_vec_t buffer;
X() : buffer( 5000000 ) { /* some more action */ }
~X() { /* some code here */ }
// the following function is called 25 times per second
const int_vec_t& process( int32_t background, const SOME_DATA& data );
};
const X::int_vec_t& X::process( int32_t background, const SOME_DATA& data )
{
// the following one string takes 30% …Run Code Online (Sandbox Code Playgroud) 是否有可能stack overflow exception在递归C++函数中捕获?如果是这样,怎么样?
那么在这种情况下会发生什么
void doWork()
{
try() {
doWork();
}
catch( ... ) {
doWork();
}
}
Run Code Online (Sandbox Code Playgroud)
我不是在寻找特定操作系统的答案.总的来说
有没有办法让enum类型无符号?以下代码向我发出有关签名/未签名比较的警告.
enum EEE {
X1 = 1
};
int main()
{
size_t x = 2;
EEE t = X1;
if ( t < x ) std::cout << "ok" << std::endl;
return 0;
}
Run Code Online (Sandbox Code Playgroud)
我试图强制编译器使用unsigned底层类型进行枚举,具体如下:
enum EEE {
X1 = 1,
XN = 18446744073709551615LL
// I've tried XN = UINT_MAX (in Visual Studio). Same warning.
};
Run Code Online (Sandbox Code Playgroud)
但这仍然是警告.
改变常量UINT_MAX使其在GNU C++中工作,应该按照标准.似乎是VS中的一个错误.感谢詹姆斯提示.
如何在加载任何链接的DLL之前停止程序?
我试图LoadLibraryExW在Break At Function调试选项中设置函数,它在该函数停止,但在此之前我在Visual Studio输出窗口中有以下内容:
'test.exe': Loaded 'C:\Windows\System32\ntdll.dll', Symbols loaded (source information stripped). 'test.exe': Loaded 'C:\Windows\System32\kernel32.dll', Symbols loaded (source information stripped). 'test.exe': Loaded 'C:\Windows\System32\KernelBase.dll', Symbols loaded (source information stripped). 'test.exe': Loaded 'C:\Windows\System32\uxtheme.dll', Symbols loaded (source information stripped). 'test.exe': Loaded 'C:\Windows\System32\msvcrt.dll', Symbols loaded (source information stripped). ---- plus about 30 DLLs ---
那么如何在加载之前在调试器中停止程序ntdll.dll呢?好的,不是在加载之前,而是在执行任何DllMain函数之前和初始化任何静态对象之前.
朋友只是抛出一些类似于以下C#代码的代码:
int i = ...;
return i < 0 ? 0 : i;
Run Code Online (Sandbox Code Playgroud)
这让我想到了.对于负整数或当前正值,有任何"不同"的方法返回零吗?更具体地说,如果可能的话,我正在寻找按位运算.
顺便说一句,我知道 Math.Max(0, i);