我是linux的新手,在使用动态库进行编译时,我收到了segmentationfault错误.
我有两个文件
ctest1.c
void ctest1(int *i)
{
*i =10;
}
Run Code Online (Sandbox Code Playgroud)
ctest2.c
void ctest2(int *i)
{
*i =20;
}
Run Code Online (Sandbox Code Playgroud)
我已使用以下命令将这两个文件编译到名为libtest.so的共享库中
gcc -shared -W1,-soname,libtest.so.1 -o libtest.so.1.0.1 ctest1.o ctest2.o -lc
Run Code Online (Sandbox Code Playgroud)
我已经编写了另一个程序prog.c,它使用了这个库导出的函数
prog.c中
#include <stdio.h>
void (*ctest1)(int*);
void (ctest2)(int*);
int main()
{
int a;
ctest1(&a);
printf("%d",a);
return 0;
}
Run Code Online (Sandbox Code Playgroud)
当我使用以下命令构建可执行文件时
gcc -Wall prog.c -L.-o prog
但是当我运行生成的可执行文件时,我得到了SegmentationFault错误.
当我用ldd检查prog的标题时,它显示出来
linux-vdso.so.1 =>(0x00007f99dff000)libc.so.6 => /lib64/libc.so.6(0x0007feeaa8c1000)/lib64/ld-linux-x86-64.so.2(0x00007feeaac1c000)
有人可以说出问题所在
我想问一下Java中哪一段代码效率更高?代码1:
void f()
{
for(int i = 0 ; i < 99999;i++)
{
for(int j = 0 ; j < 99999;j++)
{
//Some operations
}
}
}
Run Code Online (Sandbox Code Playgroud)
代码2:
void f()
{
int i,j;
for(i = 0 ; i < 99999;i++)
{
for(j = 0 ; j < 99999;j++)
{
//Some operations
}
}
}
Run Code Online (Sandbox Code Playgroud)
我的老师说第二个更好,但我不同意这个意见.
这是当前的代码:
const complex complex::operator+(const complex &right)
{
complex result;
result.realPart = realPart + right.realPart;
result.imPart = imPart + right.imPart;
return result;
}
Run Code Online (Sandbox Code Playgroud)
我该如何修改呢
a = b + c + d;
被允许?
场景:我说有4个复选框,用户可以选择任意组合的复选框(他们也有权不选择一个复选框).我必须将这4个选项存储到单个列中.我认为最好的选择是使用二进制表示存储
option1 has the constant value 1
option2 has the constant value 2
option3 has the constant value 4
option4 has the constant value 8
Run Code Online (Sandbox Code Playgroud)
因此,如果客户选择option2和option4,则存储在DB中的值将为2 + 8,即:10,如果客户选择option1,option4和option8,则值为1 + 4 + 8,即13.
另外当我从mysql查询时我可以使用
Select * from option_table where (option & 4)=4;
Run Code Online (Sandbox Code Playgroud)
如果我想检索选择了option3的行.
但由于某种原因,我无法使用这种方法,或者只是说我需要知道将这些多个值存储在一个列中的下一个最佳选择是什么?
使用dev express可以很容易地扩展Quantum Grid Views,如中所述
http://devexpress.com/Support/Center/KB/p/A334.aspx?searchtext=viewinfo
你只需声明并覆盖你需要的方法:
TMyGridDBTableView = class(TcxGridDBTableView)
protected
function GetViewInfoClass: TcxCustomGridViewInfoClass; override;
end;
Run Code Online (Sandbox Code Playgroud)
但是要为TMyGridDBTableView消磨你
或者从这样的代码构建整个UI
查看:= Grid.CreateView(TMyGridDBTableView)作为TMyGridDBTableView; View.OptionsView.ColumnAutoWidth:= True; View.OptionsView.NewItemRow:= True; View.DataController.DataSource:= DataSource1; View.DataController.CreateAllItems;
这两种方式对我都不好,因为:
有没有办法保留我已经使用表单设计的TMyGridDBTableView,但是在运行时使用TMyGridDBTableView重载方法增强了它们?
如何<p>在javascript中删除此标记及其所有内容?
说我有这个HTML代码
<p class="classname">
<input name="commit" value="Get Value" type="submit"> <span>or Cancel</span>
</p>
Run Code Online (Sandbox Code Playgroud)
现在我需要在javascript中替换/删除它,有谁知道我如何删除它?
我有一个应该转换为库的应用程序.我只复制了项目dpr并更改了源文件:
library aLibrary;
uses
FastMM4,
Forms,
SysUtils,
Windows,
Mainfrm in 'Mainfrm.pas' {Mainform};
{$R *.res}
Procedure DllMain(Reason: Integer);
Begin
If Reason = DLL_PROCESS_ATTACH Then
Begin
Application.Initialize;
Application.CreateForm(TMainForm, MainForm);
ExitCode := 0;
End;
If Reason = DLL_PROCESS_DETACH Then
Begin
Application.Terminate;
MainForm.Free;
End;
End;
Begin
DllProc := @DllMain;
DllProc(DLL_PROCESS_ATTACH);
End.
Run Code Online (Sandbox Code Playgroud)
如您所见,我只是删除了与应用程序初始化相关的通常自动生成的代码行,并将它们放入DllMain过程中,将"program"关键字更改为"library".dll加载得很好,嵌入式程序也运行良好,但我无法在主机进程中设法释放它(FreeLibrary).无论DLL_PROCESS_DETACH代码是什么,dll都会冻结(即使在这种情况下没有任何内容).
什么是释放所有应用程序的正确方法?
我试图从HTML中提取数据"Lady Gaga的名人堂怪物"的使用SUBSTR找到,但我没能检索数据.
<div class="album-name"><strong>Album</strong> > Lady Gaga Fame Monster</div>
Run Code Online (Sandbox Code Playgroud)
我试图先提取整个字符串,但我只能在命令下提取到Albumcout << line_found,因为它的间距会阻止它继续前进.
我试试cout << extract_line.我在提取的html代码中看不到空格.
我想从这个基础教程http://www.cplusplus.com/reference/string/string/substr/,它的工作原理,即使有空间.我正在密切关注但是一旦它到达空间就会停止提取.请帮助真的很感激.谢谢.找出2天没有任何解决方案.
这是源代码:
#include "parser.h"
#include <stdlib.h>
#include <iostream>
#include <fstream>
#include <string>
#include <cstring>
using namespace std;
int main() {
string line_found, extract_line, result, finalResult="";
int firstPosition, secondPosition, input, location;
ifstream sourceFile ("cd1.htm"); // extracts from sourcefile
while(!sourceFile.eof())
{
sourceFile >> extract_line;
location = extract_line.find("album-name");
// cout << extract_line;
if (location >=0)
{
line_found = extract_line.substr(location);
cout << …Run Code Online (Sandbox Code Playgroud) 当我踏上Erlang美妙世界的旅程时,我注意到它的美丽,但更重要的是我注意到它的速度.这让我很奇怪,因为Erlang非常善于生成轻量级进程,所以将它用作其他进程的包装是否有意义.
作为一个例子,我使用rspec为ruby编写测试.假设我有10,000个测试,所有测试都可以独立运行而没有任何问题.是否有意义使用Erlang生成10,000个rspec并同时运行每个测试而不是rspec顺序运行每个测试?或者这只是一个完全荒谬的想法?
我有一个使用SQLite的iOS应用程序.我使用FireFox和插件SQLite Manager来管理数据库.
现在我有一个这样的表:
CREATE TABLE "someTable" ("id" INTEGER NOT NULL , "timeOfEvent" DATETIME NOT NULL)
Run Code Online (Sandbox Code Playgroud)
然而,我几乎可以将任何我想要的值输入到DateTime列中,如下所示:
INSERT INTO sometable (id, timeOfEvent) VALUES (1,'2012-99-99')
INSERT INTO sometable (id, timeOfEvent) VALUES (2,'yyyy-mm-dd')
...etc
Run Code Online (Sandbox Code Playgroud)
为什么这可能?