我想检查g ++是否支持尾调用,所以我编写了这个简单的程序来检查它:http://ideone.com/hnXHv
using namespace std;
size_t st;
void PrintStackTop(const std::string &type)
{
int stack_top;
if(st == 0) st = (size_t) &stack_top;
cout << "In " << type << " call version, the stack top is: " << (st - (size_t) &stack_top) << endl;
}
int TailCallFactorial(int n, int a = 1)
{
PrintStackTop("tail");
if(n < 2)
return a;
return TailCallFactorial(n - 1, n * a);
}
int NormalCallFactorial(int n)
{
PrintStackTop("normal");
if(n < 2)
return 1;
return …Run Code Online (Sandbox Code Playgroud) 我正在开发内核模块,构建时间开始在我的皮肤下.作为副作用,我在构建期间采取了太多的"咖啡"休息时间.
所以我一直在寻找一种方法来构建我的平台所需的东西."Linux内核简介"的第7章和第8章详细介绍了如何手动完成.这是一个很好的阅读:http://www.kroah.com/lkn/
但是虽然我理解这些东西,但仍然需要进行大量调整才能实现这一目标.
2.6.32及更高版本的内核添加了一个新目标make localmodconfig.它会扫描lsmod并适当地更改.config.所以我以为我找到了"自动化".但是这个perl脚本也存在一些问题.
该主题描述了这些问题:https://bbs.archlinux.org/viewtopic.php?pid = 845113
还有一个显然适用于其他人的建议解决方案是直接运行脚本而不是使用make的目标.
虽然对我来说,make localmodconfig根本不起作用.它的原因如下:
make clean
make mrproper
cp /boo/config-'uname -r' .config
make localmodconfig
Run Code Online (Sandbox Code Playgroud)
它停止了
vboxguest config not found!!
nf_defrag_ipv6 config not found!!
vboxsf config not found!!
vboxvideo config not found!!
Run Code Online (Sandbox Code Playgroud)
事情是我的内核开发环境是在virtualbox里面.当我选择安装"virtualbox guest addtion"时安装了这些vbox模块.
netfilter模块可能是一个特定于分发的模块(很多netfilter模块不是主线内核的一部分,所以它对我来说不是一个冲击),它不包含在主线内核中.
现在解决方法显然卸载了这些模块并再次尝试.但我在想是否有补丁streamline_config.pl可以让用户在他/她想要时排除某些模块.问题是我零有关Perl的知识,我喜欢这样.
所以我的问题简而言之
修补,streamline_config.pl所以我可以给出一个模块名称列表作为参数,它将从处理配置文件中排除.
该脚本位于kernel.org
编辑:删除了有关perl脚本未运行的内容.正如mugen kenichi指出的那样(我多么愚蠢?).但localmodconfig由于源树下没有一些模块代码,仍然无法工作.修补streamline_config.pl仍然有效的要求.
想象一下经典的OMP任务:
using namespace std;
int main() {
vector<double> v;
// generate some data
generate_n(back_inserter(v), 1ul << 18,
bind(uniform_real_distribution<double>(0,1.0), default_random_engine { random_device {}() }));
long double sum = 0;
{
#pragma omp parallel for reduction(+:sum)
for(size_t i = 0; i < v.size(); i++)
{
sum += v[i];
}
}
std::cout << "Done: sum = " << sum << "\n";
}
Run Code Online (Sandbox Code Playgroud)
我无法想出如何报告进度.毕竟,OMP正在为我处理团队线程之间的所有协调,而我没有一个全局状态.
我可能会使用常规std::thread并从那里观察一些共享变量,但是没有更多的"omp-ish"方法来实现这一目标吗?
为了使用boost :: property_tree打印我的XML输出,我编写了以下代码:
#include <boost/property_tree/ptree.hpp>
#include <boost/property_tree/xml_parser.hpp>
int main()
{
std::string filename = "test.xml";
boost::property_tree::ptree pt;
pt.put("some.path.value", "hello");
boost::property_tree::xml_writer_settings<char> settings('\t', 1);
write_xml(filename, pt, settings);
}
Run Code Online (Sandbox Code Playgroud)
不幸的是我有这个错误,我找不到任何有关它的信息:
/usr/local/include/boost/property_tree/detail/xml_parser_writer_settings.hpp:38:19: error: type 'char' cannot be used prior to '::' because it has no members
typedef typename Str::value_type Ch;
^
Run Code Online (Sandbox Code Playgroud)
任何的想法?
我正在尝试关注railstutorial.org,目前正在第7章开始使用工厂:http://railstutorial.org/chapters/modeling-and-viewing-users-two#sec:tests_with_factories
我正在使用Rails 3.0.1和ruby-1.9.2-p0
我不能为我的生活让我的rspec测试通过,我得到的错误是
Failures:
1) UsersController GET 'show' should be successful
Failure/Error: @user = Factory(:user)
undefined method `Factory' for #<RSpec::Core::ExampleGroup::Nested_2::Nested_1:0x00000101cc5608>
# ./spec/controllers/users_controller_spec.rb:9:in `block (3 levels) in <top (required)>'
Run Code Online (Sandbox Code Playgroud)
我的factories.rb看起来像这样:
# By using the symbol ':user', we get Factory Girl to simulate the User model.
Factory.define :user do |user|
user.name "Michael Hartl"
user.email "mhartl@example.com"
user.password "foobar"
user.password_confirmation "foobar"
end
Run Code Online (Sandbox Code Playgroud)
这是我的users_controller_spec.rb档案:
require 'spec_helper'
describe UsersController do
render_views
describe "GET 'show'" do
before(:each) do
@user = Factory(:user)
end …Run Code Online (Sandbox Code Playgroud) 是否有一个框架能够删除图像的白色空间(矩形).我们从技术图纸创建图像缩略图,遗憾的是PDF格式.我们将PDF转换为SVG,然后转换为JPG.通常技术图纸非常小,现在放在缩略图的左上角:
+---------+----------------------+
| | |
| (image) | |
| | |
+---------+ |
| |
| |
| |
| |
| (empty space) |
| |
| |
+--------------------------------+
Run Code Online (Sandbox Code Playgroud)
那么如何轻松删除空白区域并缩小JPG文件呢?
在C++中使用openMP时我再次陷入困境.这次我正在尝试实现并行快速排序.
码:
#include <iostream>
#include <vector>
#include <stack>
#include <utility>
#include <omp.h>
#include <stdio.h>
#define SWITCH_LIMIT 1000
using namespace std;
template <typename T>
void insertionSort(std::vector<T> &v, int q, int r)
{
int key, i;
for(int j = q + 1; j <= r; ++j)
{
key = v[j];
i = j - 1;
while( i >= q && v[i] > key )
{
v[i+1] = v[i];
--i;
}
v[i+1] = key;
}
}
stack<pair<int,int> > s;
template <typename T>
void …Run Code Online (Sandbox Code Playgroud) 我试图让NuGet在Mono 2.10.9(Mac)上运行,但没有运气.
我想从NuGet存储库安装Nancy:
mono --runtime=v4.0 /usr/local/bin/NuGet.exe install Nancy -Version 0.11.0
Run Code Online (Sandbox Code Playgroud)
但是,最终会出现以下错误消息:
Missing method System.Security.Cryptography.CryptoConfig::get_AllowOnlyFipsAlgorithms() in assembly /Library/Frameworks/Mono.framework/Versions/2.10.9/lib/mono/4.0/mscorlib.dll, referenced in assembly /usr/local/bin/NuGet.exe
Method not found: 'System.Security.Cryptography.CryptoConfig.get_AllowOnlyFipsAlgorithms'.
Run Code Online (Sandbox Code Playgroud)
我可以毫无问题地列出存储库.
mono --runtime=v4.0 /usr/local/bin/NuGet.exe list Nancy
Run Code Online (Sandbox Code Playgroud)
我试图将Microsoft.Build.dll添加到与NuGet.exe相同的路径(来自网站的提示.我不记得在哪里).
我最终得到了这个错误:
Invalid type Microsoft.Build.Evaluation.Project for instance field NuGet.Common.MSBuildProjectSystem:<Project>k__BackingField
Could not load type 'NuGet.Common.MSBuildProjectSystem' from assembly 'NuGet, Version=2.0.30619.9000, Culture=neutral, PublicKeyToken=null'.
Run Code Online (Sandbox Code Playgroud)
有关如何在Mono(Mac)上运行NuGet.exe的任何建议?
在Boost中有3个具有手动低延迟上下文切换的细线程:
Coroutine1,Coroutine2和Boost中的Fiber之间有什么区别?
请注意以下程序,其中函数接受期望类型和作为该类型的typedef的任何类型.
//a user defined type
class Widget{};
//a function that takes a Widget
void function (Widget w){}
int main(){
//make a typedef (this is C++11 syntax for a typedef. It's the same thing)
using Gadget = Widget;
//make the two "different types" (well.. they're not really different as you will see)
Widget w;
Gadget g;
//call a function that should ONLY accept Widgets
function(w); //works (good)
function(g); //<- works (I do not want this to compile though)
}
Run Code Online (Sandbox Code Playgroud)
如您所见,typedef实际上并不区分新类型.我想改为从类型继承:
//inherit …Run Code Online (Sandbox Code Playgroud)