小编wog*_*gio的帖子

gcc警告"在GCC 7.1中为X传递的项目参数传递"是什么意思?

我有一个C++项目,可以在x86 Linux和Windows上使用gcc 7.2进行构建,并且没有警告,我需要将它移植到ARM设备上,所以我尝试使用运行在我的"arm-linux-gnueabihf"gcc 7.2交叉编译它x86机器,它构建但我得到了很多这种警告

note: parameter passing for argument of type '__gnu_cxx::__normal_iterator<P2d*, std::vector<P2d> >' changed in GCC 7.1
_M_realloc_insert(end(), __x);
Run Code Online (Sandbox Code Playgroud)

/opt/armv7-gcc-2017/arm-linux-gnueabihf/include/c++/7.2.0/bits/vector.tcc:105:21: note: parameter passing for argument of type '__gnu_cxx::__normal_iterator<cpzparser::Anchor*, std::vector<cpzparser::Anchor> >' changed in GCC 7.1
    _M_realloc_insert(end(), std::forward<_Args>(__args)...);
Run Code Online (Sandbox Code Playgroud)

要么

/opt/armv7-gcc-2017/arm-linux-gnueabihf/include/c++/7.2.0/bits/vector.tcc:394:7: note: parameter passing for argument of type 'std::vector<cpzparser::PointEntity>::iterator {aka __gnu_cxx::__normal_iterator<cpzparser::PointEntity*, std::vector<cpzparser::PointEntity> >}' changed in GCC 7.1
       vector<_Tp, _Alloc>::
Run Code Online (Sandbox Code Playgroud)

生成的可执行文件似乎工作正常,但我担心所有这些警告的存在,因为我不知道他们的意思..任何线索?

c++ gcc

21
推荐指数
1
解决办法
6901
查看次数

/ dev/random总是返回相同的序列

我打算使用/ dev/random输出作为openssl密钥生成的种子,然后我编写这个小程序只是为了检查我要做什么:

#include <stdio.h>
#include <unistd.h>
#include <fcntl.h>

#define LEN 128

void uc2hex(char* hex, unsigned char* uc, unsigned short uc_len)
{
    FILE* bp=fmemopen(hex,2*uc_len+1,"w");
    unsigned short i;
    for(i=0;i<uc_len;i++)
    {
        fprintf(bp,"%02x",uc[i]);
        //printf("%02x\n",uc[i]);
        //fprintf(bp,"%d-",i);
    }
    fprintf(bp,"%c",'\0');
    fclose(bp);
}

int main()
{
    unsigned char buf[LEN];
    char str[2*LEN+1];
    int fd=open("/dev/random",O_RDONLY);
    read(fd,buf,LEN);
    uc2hex(str,buf,LEN);
    printf("%s\n",str);
    close(fd);
    return 0;
}
Run Code Online (Sandbox Code Playgroud)

我运行程序一两次,一切似乎工作正常,但后来我再次按顺序运行了四次,这是输出:

[walter@eM350 ~]$ ./random 
0ee08c942ddf901af1278ba8f335b5df8db7cf18e5de2a67ac200f320a7a20e84866f533667a7e66a4572b3bf83d458e6f71f325783f2e3f921868328051f8f296800352cabeaf00000000000000000001000000000000005d08400000000000c080300e00000000000000000000000010084000000000000006400000000000
[walter@eM350 ~]$ ./random 
1f69a0b931c16f796bbb1345b3f58f17f74e3df600000000bb03400000000000ffffffff00000000880e648aff7f0000a88103b4d67f000000305cb4d67f000030415fb4d67f0000000000000000000001000000000000005d08400000000000c080300e00000000000000000000000010084000000000000006400000000000
[walter@eM350 ~]$ ./random 
4e8a1715238644a840eb66d9ff7f00002e4e3df600000000bb03400000000000ffffffff00000000a8ec66d9ff7f0000a871a37ad97f00000020fc7ad97f00003031ff7ad97f0000000000000000000001000000000000005d08400000000000c080300e00000000000000000000000010084000000000000006400000000000
[walter@eM350 ~]$ ./random 
598c57563e8951e6f0173f0cff7f00002e4e3df600000000bb03400000000000ffffffff0000000058193f0cff7f0000a8e1cbda257f0000009024db257f000030a127db257f0000000000000000000001000000000000005d08400000000000c080300e00000000000000000000000010084000000000000006400000000000
Run Code Online (Sandbox Code Playgroud)

除了128字节的随机字符串之外,Theese对我来说似乎很重要,因为它们大多是相同的.然后,排除NSA篡改linux内核随机数生成器的可能性,我只能猜测这与我的机器中的可用熵有关,当我在序列中询问太多字节时,它会耗尽.我的问题是:1)这个猜测是否正确?2)假设1)是正确的,我怎么知道是否有足够的熵来产生真正的随机字节序列?

c linux random

6
推荐指数
1
解决办法
790
查看次数

字符串连接和内存管理

我已经使用 C++ 一段时间了,但至少还有一件事我无法理解,我也无法在网上冲浪找到很好的解释。它与内存管理有关,可以用这个例子来说明:

考虑 std::string 的字符串连接运算符,它看起来像这样

std::string operator+(const string&s1, string&s2)

众所周知,它返回一个新创建的对象(另一个 std::string),其中包含连接的两个原始字符串。我的问题是:这怎么可能?这个对象在内存中的什么地方?

我的意思是,如果我必须编写函数实现,我会做这样的事情

std::string std::string::operator+(const string& s1, string& s2)
{
std::string *res=new std::string;
// fill res with the content of s1 and s2
return *res;
}
Run Code Online (Sandbox Code Playgroud)

但是通过这种方式我知道我会导致内存泄漏,因为如果我调用该函数一百万次,我将生成一百万个字符串,这些字符串在程序结束之前不会被释放。另一方面,我可以这样做:

std::string& std::string::operator+(const string& s1, string& s2)
{
std::string res;
// fill res with the content of s1 and s2
return res;
}
Run Code Online (Sandbox Code Playgroud)

但是通过这种方式,我会返回对局部变量的引用,一旦函数返回,该变量就会变成垃圾。最后我可以简单地写

std::string std::string::operator+(const string& s1, string& s2)
{
std::string res;
// fill res with the content of s1 and s2
return …
Run Code Online (Sandbox Code Playgroud)

c++ memory-management

3
推荐指数
1
解决办法
1681
查看次数

tp_clear,tp_dealloc和tp_free有什么区别?

我有一个用于模糊字符串搜索的自定义python模块,实现了Levenshtein距离计算,它包含一个称为levtree的python类型,它具有两个成员,该指针指向执行所有计算的wlevtree C类型(称为tree)的指针和指向的PyObject * python字符串的python列表,称为wordlist。这是我需要的:

-当我创建levtree的新实例时,我使用一个构造函数,该构造函数将字符串元组作为其唯一输入(并且该字典将在其中实例执行所有搜索),该构造函数将必须创建levtree的新实例。将wordlist添加到levtree的新实例中,然后将输入元组的内容复制到wordlist的新实例中。这是我的第一个代码段和第一个问题:

static int
wlevtree_python_init(wlevtree_wlevtree_obj *self, PyObject *args, PyObject *kwds)
{
    int numLines;       /* how many lines we passed for parsing */
    wchar_t** carg;        /* argument to pass to the C function*/
    unsigned i;

    PyObject * strObj;  /* one string in the list */
    PyObject* intuple;

    /* the O! parses for a Python object (listObj) checked
      to be of type PyList_Type */
    if (!(PyArg_ParseTuple(args, "O!", &PyTuple_Type, &intuple)))
    {
        return -1;
    }

    /* get the number of lines …
Run Code Online (Sandbox Code Playgroud)

c python python-extensions

3
推荐指数
1
解决办法
1076
查看次数

标签 统计

c ×2

c++ ×2

gcc ×1

linux ×1

memory-management ×1

python ×1

python-extensions ×1

random ×1