error: passing ‘const HasPtr’as‘this’argument of‘HasPtr& HasPtr::operator=(const HasPtr&)’discards qualifiers [-fpermissive]

如题:
HasPtr.h

#include <iostream>
#include <string>

class HasPtr {
public:
    HasPtr(const std::string &s, int a)
        : ps(new std::string(s)), i(a) {}
    HasPtr(const std::string &s = std::string())
        : ps(new std::string()), i(0) {}
    HasPtr(const HasPtr &obj)
        : ps(new std::string(*obj.ps)), i(obj.i) {
            std::cout << "Copy constructor execute" << std::endl;
        }
    HasPtr & operator=(const HasPtr &rhs) {
        ps = new std::string(*rhs.ps);
        i = rhs.i;
        return *this;
    }
    ~HasPtr() {
        delete ps;
    }

    std::string get_str() const {
        return *ps;
    }

    int get_i() const {
        return i;
    }
    bool operator<(const HasPtr obj) const {
        return i < obj.i;
    }

    friend void swap(HasPtr &lhs, HasPtr &rhs) {
        std::swap(lhs.ps, rhs.ps);
        std::swap(lhs.i, rhs.i);
    }

private:
    std::string *ps;
    int i;
};

main.cpp

#include <iostream>
#include <vector>
#include <algorithm>
#include "HasPtr.h"


int main() {
    size_t n = 3;
    std::vector<HasPtr> v;
    for (size_t i = 0; i < n; ++i) {
        v.push_back(std::to_string(i));
    }

    sort(v.cbegin(), v.cend());
}

遇到错误:

error: passing ‘const HasPtr’ as ‘this’ argument of ‘HasPtr& HasPtr::operator=(const HasPtr&)’ discards qualifiers [-fpermissive]

之前搜索的大多数答案是成员函数不是const类型的。但是我的问题处在拷贝赋值运算符上,没有理由要把拷贝赋值运算符也写成const类型对吗?

u014786409
小飞将 如果我使用常量迭代器,重载的operator<()不使用常量版本,又会报出之前的错误,那么sort()中为什么会出现const HasPtr呢?按理说都是非常量的才对。
8 个月之前 回复
u014786409
小飞将 问题出在sort的参数类型是const上,应该传入普通迭代器而不是常量迭代器。
8 个月之前 回复

1个回答

Csdn user default icon
上传中...
上传图片
插入图片
抄袭、复制答案,以达到刷声望分或其他目的的行为,在CSDN问答是严格禁止的,一经发现立刻封号。是时候展现真正的技术了!
其他相关推荐
error: passing ‘const HasPtr’as‘this’argument of‘HasPtr& HasPtr::operator=(const HasPtr&)’discards qualifiers [-fpermissive]

如题: HasPtr.h ``` #include <iostream> #include <string> class HasPtr { public: HasPtr(const std::string &s, int a) : ps(new std::string(s)), i(a) {} HasPtr(const std::string &s = std::string()) : ps(new std::string()), i(0) {} HasPtr(const HasPtr &obj) : ps(new std::string(*obj.ps)), i(obj.i) { std::cout << "Copy constructor execute" << std::endl; } HasPtr & operator=(const HasPtr &rhs) { ps = new std::string(*rhs.ps); i = rhs.i; return *this; } ~HasPtr() { delete ps; } std::string get_str() const { return *ps; } int get_i() const { return i; } bool operator<(const HasPtr obj) const { return i < obj.i; } friend void swap(HasPtr &lhs, HasPtr &rhs) { std::swap(lhs.ps, rhs.ps); std::swap(lhs.i, rhs.i); } private: std::string *ps; int i; }; ``` main.cpp ``` #include <iostream> #include <vector> #include <algorithm> #include "HasPtr.h" int main() { size_t n = 3; std::vector<HasPtr> v; for (size_t i = 0; i < n; ++i) { v.push_back(std::to_string(i)); } sort(v.cbegin(), v.cend()); } ``` 遇到错误: ``` error: passing ‘const HasPtr’ as ‘this’ argument of ‘HasPtr& HasPtr::operator=(const HasPtr&)’ discards qualifiers [-fpermissive] ``` 之前搜索的大多数答案是成员函数不是const类型的。但是我的问题处在拷贝赋值运算符上,没有理由要把拷贝赋值运算符也写成const类型对吗?

mod_jk报错,哪位大侠帮忙解答下

[root@langhuaqi-353 native]# make Making all in common make[1]: Entering directory `/usr/local/src/jakarta-tomcat-connectors-1.2.15-src/jk/native/common' make[1]: Nothing to be done for `all'. make[1]: Leaving directory `/usr/local/src/jakarta-tomcat-connectors-1.2.15-src/jk/native/common' Making all in apache-2.0 make[1]: Entering directory `/usr/local/src/jakarta-tomcat-connectors-1.2.15-src/jk/native/apache-2.0' /usr/local/apache2/build/libtool --silent --mode=compile gcc -std=gnu99 -I/usr/local/apache2/include -g -O2 -DUSE_APACHE_MD5 -I ../common -I /root/jdk1.6.0_20/include -I /root/jdk1.6.0_20/include/unix -DLINUX=2 -D_REENTRANT -D_GNU_SOURCE -g -O2 -pthread -DHAVE_APR -I/usr/local/apache2/include -I/usr/local/apache2/include -g -O2 -g -O2 -pthread -DLINUX=2 -D_REENTRANT -D_GNU_SOURCE -c mod_jk.c -o mod_jk.lo mod_jk.c: In function 'jk_error_exit': mod_jk.c:446: warning: initialization from incompatible pointer type mod_jk.c:446: error: expected expression before ')' token mod_jk.c:446: warning: passing argument 5 of 'ap_log_error_' makes integer from pointer without a cast /usr/local/apache2/include/http_log.h:372: note: expected 'apr_status_t' but argument is of type 'const struct server_rec *' mod_jk.c: In function 'init_ws_service': mod_jk.c:499: error: 'conn_rec' has no member named 'remote_ip' mod_jk.c:499: error: 'conn_rec' has no member named 'remote_ip' mod_jk.c:499: error: 'conn_rec' has no member named 'remote_ip' mod_jk.c:515: warning: implicit declaration of function 'ap_get_server_version' mod_jk.c:515: warning: cast to pointer from integer of different size mod_jk.c:542: error: 'conn_rec' has no member named 'remote_ip' mod_jk.c:542: error: 'conn_rec' has no member named 'remote_ip' mod_jk.c: At top level: mod_jk.c:1684: warning: initialization from incompatible pointer type mod_jk.c:1692: warning: initialization from incompatible pointer type mod_jk.c: In function 'create_jk_config': mod_jk.c:2091: warning: passing argument 5 of 'jk_error_exit' from incompatible pointer type mod_jk.c:433: note: expected 'struct apr_pool_t *' but argument is of type 'struct server_rec *' mod_jk.c:2091: warning: passing argument 6 of 'jk_error_exit' from incompatible pointer type mod_jk.c:433: note: expected 'const char *' but argument is of type 'struct apr_pool_t *' mod_jk.c:2094: warning: passing argument 5 of 'jk_error_exit' from incompatible pointer type mod_jk.c:433: note: expected 'struct apr_pool_t *' but argument is of type 'struct server_rec *' mod_jk.c:2094: warning: passing argument 6 of 'jk_error_exit' from incompatible pointer type mod_jk.c:433: note: expected 'const char *' but argument is of type 'struct apr_pool_t *' mod_jk.c: In function 'copy_jk_map': mod_jk.c:2123: warning: passing argument 5 of 'jk_error_exit' from incompatible pointer type mod_jk.c:433: note: expected 'struct apr_pool_t *' but argument is of type 'struct server_rec *' mod_jk.c:2123: warning: passing argument 6 of 'jk_error_exit' from incompatible pointer type mod_jk.c:433: note: expected 'const char *' but argument is of type 'struct apr_pool_t *' mod_jk.c: In function 'merge_jk_config': mod_jk.c:2163: warning: passing argument 5 of 'jk_error_exit' from incompatible pointer type mod_jk.c:433: note: expected 'struct apr_pool_t *' but argument is of type 'struct server_rec *' mod_jk.c:2163: warning: passing argument 6 of 'jk_error_exit' from incompatible pointer type mod_jk.c:433: note: expected 'const char *' but argument is of type 'struct apr_pool_t *' mod_jk.c: In function 'jk_log_to_file': mod_jk.c:2204: error: request for member 'log' in something not a structure or union mod_jk.c:2204: error: request for member 'log' in something not a structure or union mod_jk.c:2204: error: request for member 'connection' in something not a structure or union mod_jk.c:2204: error: request for member 'connection' in something not a structure or union mod_jk.c:2204: error: request for member 'server' in something not a structure or union mod_jk.c:2204: error: request for member 'log' in something not a structure or union mod_jk.c:2204: error: request for member 'log' in something not a structure or union mod_jk.c:2204: error: request for member 'connection' in something not a structure or union mod_jk.c:2204: error: request for member 'connection' in something not a structure or union mod_jk.c:2204: error: request for member 'server' in something not a structure or union mod_jk.c:2204: error: request for member 'log' in something not a structure or union mod_jk.c:2204: error: request for member 'log' in something not a structure or union mod_jk.c:2204: error: request for member 'connection' in something not a structure or union mod_jk.c:2204: error: request for member 'connection' in something not a structure or union mod_jk.c:2204: error: request for member 'server' in something not a structure or union mod_jk.c:2204: error: request for member 'log' in something not a structure or union mod_jk.c:2204: error: request for member 'log' in something not a structure or union mod_jk.c:2204: error: request for member 'connection' in something not a structure or union mod_jk.c:2204: error: request for member 'connection' in something not a structure or union mod_jk.c:2204: error: request for member 'server' in something not a structure or union mod_jk.c: In function 'init_jk': mod_jk.c:2395: warning: passing argument 5 of 'jk_error_exit' from incompatible pointer type mod_jk.c:433: note: expected 'struct apr_pool_t *' but argument is of type 'struct server_rec *' mod_jk.c:2395: warning: passing argument 6 of 'jk_error_exit' from incompatible pointer type mod_jk.c:433: note: expected 'const char *' but argument is of type 'struct apr_pool_t *' mod_jk.c:2413: warning: cast to pointer from integer of different size mod_jk.c: In function 'jk_post_config': mod_jk.c:2437: warning: implicit declaration of function 'unixd_set_global_mutex_perms' make[1]: *** [mod_jk.lo] Error 1 make[1]: Leaving directory `/usr/local/src/jakarta-tomcat-connectors-1.2.15-src/jk/native/apache-2.0' make: *** [all-recursive] Error 1

c++ class重载比较运算符的写法

本地能编译通过,但是在一个脑残oj上RE了。。不知道是不是哪里写的不规范 ``` /usr/lib/gcc/i386-redhat-linux/4.1.2/../../../../include/c++/4.1.2/bits/stl_algo.h: In function ‘const _Tp& std::__median(const _Tp&, const _Tp&, const _Tp&) [with _Tp = S]’: /usr/lib/gcc/i386-redhat-linux/4.1.2/../../../../include/c++/4.1.2/bits/stl_algo.h:2642: instantiated from ‘void std::__introsort_loop(_RandomAccessIterator, _RandomAccessIterator, _Size) [with _RandomAccessIterator = S*, _Size = int]’ /usr/lib/gcc/i386-redhat-linux/4.1.2/../../../../include/c++/4.1.2/bits/stl_algo.h:2713: instantiated from ‘void std::sort(_RandomAccessIterator, _RandomAccessIterator) [with _RandomAccessIterator = S*]’ /main.cxx:34: instantiated from here /usr/lib/gcc/i386-redhat-linux/4.1.2/../../../../include/c++/4.1.2/bits/stl_algo.h:91: error: passing ‘const S’ as ‘this’ argument of ‘bool S::operator<(const S&)’ discards qualifiers /usr/lib/gcc/i386-redhat-linux/4.1.2/../../../../include/c++/4.1.2/bits/stl_algo.h:92: error: passing ‘const S’ as ‘this’ argument of ‘bool S::operator<(const S&)’ discards qualifiers /usr/lib/gcc/i386-redhat-linux/4.1.2/../../../../include/c++/4.1.2/bits/stl_algo.h:94: error: passing ‘const S’ as ‘this’ argument of ‘bool S::operator<(const S&)’ discards qualifiers /usr/lib/gcc/i386-redhat-linux/4.1.2/../../../../include/c++/4.1.2/bits/stl_algo.h:98: error: passing ‘const S’ as ‘this’ argument of ‘bool S::operator<(const S&)’ discards qualifiers /usr/lib/gcc/i386-redhat-linux/4.1.2/../../../../include/c++/4.1.2/bits/stl_algo.h:100: error: passing ‘const S’ as ‘this’ argument of ‘bool S::operator<(const S&)’ discards qualifiers ``` 以上是错误提示。。 ```c++ class S{ public: int l,r; S* nxt; S(int x,int y){ l=x; r=y; nxt=NULL; } S(){ l=0; r=0; nxt=NULL; } int con(){ if(nxt->l<=r) return 1; else return 0; } bool operator <(const S& next){ if(l<next.l) return 1; else return 0; } }; ``` 后面用到了sort ```c++ sort(seg+1,seg+n+1); ```

make:*** [php_mongo.lo]错误1

<div class="post-text" itemprop="text"> <p>When I installed the Mongo PHP extension, the following error occurred when I tried to compile the file.</p> <p><img src="https://i.stack.imgur.com/iqaqz.png" alt="This is a picture"></p> <ul> <li>PHP version is 7, </li> <li>MongoDB version is 3.0.6.</li> </ul> <p>The error</p> <pre><code>/bin/sh /root/mongo-1.6.0/libtool --mode=compile cc -I./util -I. -I/root/mongo-1.6.0 -DPHP_ATOM_INC -I/root/mongo-1.6.0/include -I/root/mongo-1.6.0/main -I/root/mongo-1.6.0 -I/usr/local/php/include/php -I/usr/local/php/include/php/main -I/usr/local/php/include/php/TSRM -I/usr/local/php/include/php/Zend -I/usr/local/php/include/php/ext -I/usr/local/php/include/php/ext/date/lib -I/root/mongo-1.6.0/api -I/root/mongo-1.6.0/util -I/root/mongo-1.6.0/exceptions -I/root/mongo-1.6.0/gridfs -I/root/mongo-1.6.0/types -I/root/mongo-1.6.0/batch -I/root/mongo-1.6.0/contrib -I/root/mongo-1.6.0/mcon -I/root/mongo-1.6.0/mcon/contrib -DHAVE_CONFIG_H -g -O2 -c /root/mongo-1.6.0/php_mongo.c -o php_mongo.lo mkdir .libs cc -I./util -I. -I/root/mongo-1.6.0 -DPHP_ATOM_INC -I/root/mongo-1.6.0/include -I/root/mongo-1.6.0/main -I/root/mongo-1.6.0 -I/usr/local/php/include/php -I/usr/local/php/include/php/main -I/usr/local/php/include/php/TSRM -I/usr/local/php/include/php/Zend -I/usr/local/php/include/php/ext -I/usr/local/php/include/php/ext/date/lib -I/root/mongo-1.6.0/api -I/root/mongo-1.6.0/util -I/root/mongo-1.6.0/exceptions -I/root/mongo-1.6.0/gridfs -I/root/mongo-1.6.0/types -I/root/mongo-1.6.0/batch -I/root/mongo-1.6.0/contrib -I/root/mongo-1.6.0/mcon -I/root/mongo-1.6.0/mcon/contrib -DHAVE_CONFIG_H -g -O2 -c /root/mongo-1.6.0/php_mongo.c -fPIC -DPIC -o .libs/php_mongo.o In file included from /root/mongo-1.6.0/php_mongo.c:22: /root/mongo-1.6.0/php_mongo.h:197: error: expected ‘=’, ‘,’, ‘;’, ‘asm’ or ‘__attribute__’ before ‘php_mongo_type_object_new’ /root/mongo-1.6.0/php_mongo.h:201: error: expected ‘;’, ‘,’ or ‘)’ before ‘*’ token /root/mongo-1.6.0/php_mongo.h:207: error: expected ‘;’, ‘,’ or ‘)’ before ‘*’ token In file included from /root/mongo-1.6.0/php_mongo.c:24: /root/mongo-1.6.0/mongoclient.h:19: error: expected ‘=’, ‘,’, ‘;’, ‘asm’ or ‘__attribute__’ before ‘php_mongoclient_new’ In file included from /root/mongo-1.6.0/php_mongo.c:43: /root/mongo-1.6.0/types/id.h:19: error: expected declaration specifiers or ‘...’ before ‘zend_uint’ /root/mongo-1.6.0/types/id.h:20: error: expected declaration specifiers or ‘...’ before ‘zend_uint’ /root/mongo-1.6.0/php_mongo.c: In function ‘OnUpdatePingInterval’: /root/mongo-1.6.0/php_mongo.c:127: error: ‘new_value_length’ undeclared (first use in this function) /root/mongo-1.6.0/php_mongo.c:127: error: (Each undeclared identifier is reported only once /root/mongo-1.6.0/php_mongo.c:127: error: for each function it appears in.) /root/mongo-1.6.0/php_mongo.c:127: warning: passing argument 1 of ‘is_numeric_string’ from incompatible pointer type /usr/local/php/include/php/Zend/zend_operators.h:138: note: expected ‘const char *’ but argument is of type ‘struct zend_string *’ /root/mongo-1.6.0/php_mongo.c: In function ‘OnUpdateIsMasterInterval’: /root/mongo-1.6.0/php_mongo.c:139: error: ‘new_value_length’ undeclared (first use in this function) /root/mongo-1.6.0/php_mongo.c:139: warning: passing argument 1 of ‘is_numeric_string’ from incompatible pointer type /usr/local/php/include/php/Zend/zend_operators.h:138: note: expected ‘const char *’ but argument is of type ‘struct zend_string *’ /root/mongo-1.6.0/php_mongo.c: In function ‘zm_startup_mongo’: /root/mongo-1.6.0/php_mongo.c:236: error: ‘mongo_read_property’ undeclared (first use in this function) /root/mongo-1.6.0/php_mongo.c:237: error: ‘mongo_write_property’ undeclared (first use in this function) /root/mongo-1.6.0/php_mongo.c: At top level: /root/mongo-1.6.0/php_mongo.c:481: error: expected ‘=’, ‘,’, ‘;’, ‘asm’ or ‘__attribute__’ before ‘php_mongo_type_object_new’ /root/mongo-1.6.0/php_mongo.c:496:57: error: macro "zend_hash_get_current_data" passed 2 arguments, but takes just 1 /root/mongo-1.6.0/php_mongo.c: In function ‘get_tagset_from_array’: /root/mongo-1.6.0/php_mongo.c:496: error: ‘zend_hash_get_current_data’ undeclared (first use in this function) /root/mongo-1.6.0/php_mongo.c:505: warning: passing argument 2 of ‘zend_hash_get_current_key_ex’ from incompatible pointer type /usr/local/php/include/php/Zend/zend_hash.h:168: note: expected ‘struct zend_string **’ but argument is of type ‘char **’ /root/mongo-1.6.0/php_mongo.c:505: warning: passing argument 3 of ‘zend_hash_get_current_key_ex’ from incompatible pointer type /usr/local/php/include/php/Zend/zend_hash.h:168: note: expected ‘zend_ulong *’ but argument is of type ‘uint *’ /root/mongo-1.6.0/php_mongo.c:505: warning: passing argument 4 of ‘zend_hash_get_current_key_ex’ from incompatible pointer type /usr/local/php/include/php/Zend/zend_hash.h:168: note: expected ‘HashPosition *’ but argument is of type ‘ulong *’ /root/mongo-1.6.0/php_mongo.c:505: error: too many arguments to function ‘zend_hash_get_current_key_ex’ /root/mongo-1.6.0/php_mongo.c:511: warning: passing argument 3 of ‘mongo_read_preference_add_tag’ makes pointer from integer without a cast /root/mongo-1.6.0/mcon/read_preference.h:51: note: expected ‘char *’ but argument is of type ‘int’ /root/mongo-1.6.0/php_mongo.c:553:47: error: macro "add_assoc_string" passed 4 arguments, but takes just 3 /root/mongo-1.6.0/php_mongo.c: In function ‘php_mongo_make_tagsets’: /root/mongo-1.6.0/php_mongo.c:553: error: ‘add_assoc_string’ undeclared (first use in this function) /root/mongo-1.6.0/php_mongo.c:587:61: error: macro "zend_hash_get_current_data" passed 2 arguments, but takes just 1 /root/mongo-1.6.0/php_mongo.c: In function ‘php_mongo_use_tagsets’: /root/mongo-1.6.0/php_mongo.c:587: error: ‘zend_hash_get_current_data’ undeclared (first use in this function) /root/mongo-1.6.0/php_mongo.c: In function ‘php_mongo_trigger_error_on_command_failure’: /root/mongo-1.6.0/php_mongo.c:658: warning: passing argument 2 of ‘zend_hash_find’ from incompatible pointer type /usr/local/php/include/php/Zend/zend_hash.h:154: note: expected ‘struct zend_string *’ but argument is of type ‘char *’ /root/mongo-1.6.0/php_mongo.c:658: error: too many arguments to function ‘zend_hash_find’ /root/mongo-1.6.0/php_mongo.c:664: warning: passing argument 2 of ‘zend_hash_find’ from incompatible pointer type /usr/local/php/include/php/Zend/zend_hash.h:154: note: expected ‘struct zend_string *’ but argument is of type ‘char *’ /root/mongo-1.6.0/php_mongo.c:664: error: too many arguments to function ‘zend_hash_find’ /root/mongo-1.6.0/php_mongo.c:665: warning: passing argument 1 of ‘zval_get_type’ from incompatible pointer type /usr/local/php/include/php/Zend/zend_types.h:326: note: expected ‘const struct zval *’ but argument is of type ‘struct zval **’ /root/mongo-1.6.0/php_mongo.c:665: warning: passing argument 1 of ‘zval_get_type’ from incompatible pointer type /usr/local/php/include/php/Zend/zend_types.h:326: note: expected ‘const struct zval *’ but argument is of type ‘struct zval **’ /root/mongo-1.6.0/php_mongo.c:665: warning: passing argument 1 of ‘_convert_to_string’ from incompatible pointer type /usr/local/php/include/php/Zend/zend_operators.h:243: note: expected ‘struct zval *’ but argument is of type ‘struct zval **’ /root/mongo-1.6.0/php_mongo.c:666: warning: assignment makes pointer from integer without a cast /root/mongo-1.6.0/php_mongo.c:671: warning: passing argument 2 of ‘zend_hash_find’ from incompatible pointer type /usr/local/php/include/php/Zend/zend_hash.h:154: note: expected ‘struct zend_string *’ but argument is of type ‘char *’ /root/mongo-1.6.0/php_mongo.c:671: error: too many arguments to function ‘zend_hash_find’ /root/mongo-1.6.0/php_mongo.c:672: warning: passing argument 1 of ‘zval_get_type’ from incompatible pointer type /usr/local/php/include/php/Zend/zend_types.h:326: note: expected ‘const struct zval *’ but argument is of type ‘struct zval **’ /root/mongo-1.6.0/php_mongo.c:672: warning: passing argument 1 of ‘convert_to_long’ from incompatible pointer type /usr/local/php/include/php/Zend/zend_operators.h:244: note: expected ‘struct zval *’ but argument is of type ‘struct zval **’ /root/mongo-1.6.0/php_mongo.c:685: error: too many arguments to function ‘zend_hash_copy’ /root/mongo-1.6.0/php_mongo.c:687: warning: passing argument 1 of ‘_zval_ptr_dtor’ from incompatible pointer type /usr/local/php/include/php/Zend/zend_variables.h:112: note: expected ‘struct zval *’ but argument is of type ‘struct zval **’ /root/mongo-1.6.0/php_mongo.c: In function ‘php_mongo_trigger_error_on_gle’: /root/mongo-1.6.0/php_mongo.c:708: warning: passing argument 2 of ‘zend_hash_find’ from incompatible pointer type /usr/local/php/include/php/Zend/zend_hash.h:154: note: expected ‘struct zend_string *’ but argument is of type ‘char *’ /root/mongo-1.6.0/php_mongo.c:708: error: too many arguments to function ‘zend_hash_find’ /root/mongo-1.6.0/php_mongo.c:716: warning: passing argument 2 of ‘zend_hash_find’ from incompatible pointer type /usr/local/php/include/php/Zend/zend_hash.h:154: note: expected ‘struct zend_string *’ but argument is of type ‘char *’ /root/mongo-1.6.0/php_mongo.c:716: error: too many arguments to function ‘zend_hash_find’ /root/mongo-1.6.0/php_mongo.c:717: warning: passing argument 1 of ‘zval_get_type’ from incompatible pointer type /usr/local/php/include/php/Zend/zend_types.h:326: note: expected ‘const struct zval *’ but argument is of type ‘struct zval **’ /root/mongo-1.6.0/php_mongo.c:717: warning: passing argument 1 of ‘convert_to_long’ from incompatible pointer type /usr/local/php/include/php/Zend/zend_operators.h:244: note: expected ‘struct zval *’ but argument is of type ‘struct zval **’ /root/mongo-1.6.0/php_mongo.c:724: warning: passing argument 2 of ‘zend_hash_find’ from incompatible pointer type /usr/local/php/include/php/Zend/zend_hash.h:154: note: expected ‘struct zend_string *’ but argument is of type ‘char *’ /root/mongo-1.6.0/php_mongo.c:724: error: too many arguments to function ‘zend_hash_find’ /root/mongo-1.6.0/php_mongo.c:736: error: too many arguments to function ‘zend_hash_copy’ /root/mongo-1.6.0/php_mongo.c:738: warning: passing argument 1 of ‘_zval_ptr_dtor’ from incompatible pointer type /usr/local/php/include/php/Zend/zend_variables.h:112: note: expected ‘struct zval *’ but argument is of type ‘struct zval **’ make: *** [php_mongo.lo] Error 1 </code></pre> </div>

RHEL 6.0 64位无线网卡驱动安装求教!

网上爬了段时间,终于找到了RHEL6.0的64位驱动,是官方的。用Linux不久,请知道的大哥大姐指教!!!下面介绍下我的系统信息: 我的系统是RHEL 6.0 64位的,装载笔记本上(非虚拟机),这是我的系统信息: Linux jingle.PC 2.6.32-358.el6.x86_64 #1 SMP Tue Jan 29 11:47:41 EST 2013 x86_64 x86_64 x86_64 GNU/Linux ——————————————————————————————————————————————————— \# lspci -n | grep 14e4 06:00.0 0280: 14e4:4315 (rev 01) 08:00.0 0200: 14e4:1698 (rev 10) ——————————————————————————————————————————————————— 无线网卡信息: 06:00.0 Network controller: Broadcom Corporation BCM4312 802.11b/g LP-PHY (rev 01) ——————————————————————————————————————————————————— 下面是我执行make命令时提示的信息: KBUILD_NOPEDANTIC=1 make -C /lib/modules/`uname -r`/build M=`pwd` make[1]: Entering directory `/usr/src/kernels/2.6.32-358.el6.x86_64' CFG80211 API is prefered for this kernel version Using CFG80211 API LD /root/hybrid_wl/built-in.o CC [M] /root/hybrid_wl/src/shared/linux_osl.o CC [M] /root/hybrid_wl/src/wl/sys/wl_linux.o CC [M] /root/hybrid_wl/src/wl/sys/wl_iw.o CC [M] /root/hybrid_wl/src/wl/sys/wl_cfg80211_hybrid.o /root/hybrid_wl/src/wl/sys/wl_cfg80211_hybrid.c:79: warning: ‘enum tx_power_setting’ declared inside parameter list /root/hybrid_wl/src/wl/sys/wl_cfg80211_hybrid.c:79: warning: its scope is only this definition or declaration, which is probably not what you want /root/hybrid_wl/src/wl/sys/wl_cfg80211_hybrid.c:1092: warning: ‘enum tx_power_setting’ declared inside parameter list /root/hybrid_wl/src/wl/sys/wl_cfg80211_hybrid.c:1092: error: parameter 2 (‘type’) has incomplete type /root/hybrid_wl/src/wl/sys/wl_cfg80211_hybrid.c: In function ‘wl_cfg80211_set_tx_power’: /root/hybrid_wl/src/wl/sys/wl_cfg80211_hybrid.c:1103: error: ‘TX_POWER_AUTOMATIC’ undeclared (first use in this function) /root/hybrid_wl/src/wl/sys/wl_cfg80211_hybrid.c:1103: error: (Each undeclared identifier is reported only once /root/hybrid_wl/src/wl/sys/wl_cfg80211_hybrid.c:1103: error: for each function it appears in.) /root/hybrid_wl/src/wl/sys/wl_cfg80211_hybrid.c:1105: error: ‘TX_POWER_LIMITED’ undeclared (first use in this function) /root/hybrid_wl/src/wl/sys/wl_cfg80211_hybrid.c:1111: error: ‘TX_POWER_FIXED’ undeclared (first use in this function) /root/hybrid_wl/src/wl/sys/wl_cfg80211_hybrid.c: At top level: /root/hybrid_wl/src/wl/sys/wl_cfg80211_hybrid.c:1594: warning: initialization from incompatible pointer type /root/hybrid_wl/src/wl/sys/wl_cfg80211_hybrid.c:1596: warning: initialization from incompatible pointer type /root/hybrid_wl/src/wl/sys/wl_cfg80211_hybrid.c:1597: warning: initialization from incompatible pointer type /root/hybrid_wl/src/wl/sys/wl_cfg80211_hybrid.c:1598: warning: initialization from incompatible pointer type /root/hybrid_wl/src/wl/sys/wl_cfg80211_hybrid.c:1599: warning: initialization from incompatible pointer type /root/hybrid_wl/src/wl/sys/wl_cfg80211_hybrid.c: In function ‘wl_inform_single_bss’: /root/hybrid_wl/src/wl/sys/wl_cfg80211_hybrid.c:1764: error: too few arguments to function ‘ieee80211_channel_to_frequency’ /root/hybrid_wl/src/wl/sys/wl_cfg80211_hybrid.c: In function ‘wl_bss_roaming_done’: /root/hybrid_wl/src/wl/sys/wl_cfg80211_hybrid.c:2090: warning: passing argument 2 of ‘cfg80211_roamed’ from incompatible pointer type include/net/cfg80211.h:3124: note: expected ‘struct ieee80211_channel *’ but argument is of type ‘u8 *’ /root/hybrid_wl/src/wl/sys/wl_cfg80211_hybrid.c:2090: warning: passing argument 4 of ‘cfg80211_roamed’ makes pointer from integer without a cast include/net/cfg80211.h:3124: note: expected ‘const u8 *’ but argument is of type ‘s32’ /root/hybrid_wl/src/wl/sys/wl_cfg80211_hybrid.c:2090: warning: passing argument 5 of ‘cfg80211_roamed’ makes integer from pointer without a cast include/net/cfg80211.h:3124: note: expected ‘size_t’ but argument is of type ‘u8 *’ /root/hybrid_wl/src/wl/sys/wl_cfg80211_hybrid.c:2090: warning: passing argument 6 of ‘cfg80211_roamed’ makes pointer from integer without a cast include/net/cfg80211.h:3124: note: expected ‘const u8 *’ but argument is of type ‘s32’ /root/hybrid_wl/src/wl/sys/wl_cfg80211_hybrid.c:2090: error: too few arguments to function ‘cfg80211_roamed’ /root/hybrid_wl/src/wl/sys/wl_cfg80211_hybrid.c: In function ‘wl_bss_connect_done’: /root/hybrid_wl/src/wl/sys/wl_cfg80211_hybrid.c:2122: warning: passing argument 2 of ‘cfg80211_roamed’ from incompatible pointer type include/net/cfg80211.h:3124: note: expected ‘struct ieee80211_channel *’ but argument is of type ‘u8 *’ /root/hybrid_wl/src/wl/sys/wl_cfg80211_hybrid.c:2122: warning: passing argument 4 of ‘cfg80211_roamed’ makes pointer from integer without a cast include/net/cfg80211.h:3124: note: expected ‘const u8 *’ but argument is of type ‘s32’ /root/hybrid_wl/src/wl/sys/wl_cfg80211_hybrid.c:2122: warning: passing argument 5 of ‘cfg80211_roamed’ makes integer from pointer without a cast include/net/cfg80211.h:3124: note: expected ‘size_t’ but argument is of type ‘u8 *’ /root/hybrid_wl/src/wl/sys/wl_cfg80211_hybrid.c:2122: warning: passing argument 6 of ‘cfg80211_roamed’ makes pointer from integer without a cast include/net/cfg80211.h:3124: note: expected ‘const u8 *’ but argument is of type ‘s32’ /root/hybrid_wl/src/wl/sys/wl_cfg80211_hybrid.c:2122: error: too few arguments to function ‘cfg80211_roamed’ make[2]: *** [/root/hybrid_wl/src/wl/sys/wl_cfg80211_hybrid.o] Error 1 make[1]: *** [_module_/root/hybrid_wl] Error 2 make[1]: Leaving directory `/usr/src/kernels/2.6.32-358.el6.x86_64' make: *** [all] Error 2

安装 tengine异常,求解

请教大神!!! 安装tengine-2.2.0 异常 src/event/ngx_event_openssl.c: In function ‘ngx_ssl_init’: src/event/ngx_event_openssl.c:112:5: error: ‘OPENSSL_config’ is deprecated [-Werror=deprecated-declarations] OPENSSL_config(NULL); ^ In file included from /usr/local/include/openssl/ct.h:13:0, from /usr/local/include/openssl/ssl.h:61, from src/event/ngx_event_openssl.h:15, from src/core/ngx_core.h:85, from src/event/ngx_event_openssl.c:9: /usr/local/include/openssl/conf.h:92:1: note: declared here DEPRECATEDIN_1_1_0(void OPENSSL_config(const char *config_name)) ^ src/event/ngx_event_openssl.c: In function ‘ngx_ssl_rsa512_key_callback’: src/event/ngx_event_openssl.c:753:9: error: ‘RSA_generate_key’ is deprecated [-Werror=deprecated-declarations] key = RSA_generate_key(512, RSA_F4, NULL, NULL); ^ In file included from /usr/local/include/openssl/rsa.h:13:0, from /usr/local/include/openssl/x509.h:31, from /usr/local/include/openssl/ssl.h:50, from src/event/ngx_event_openssl.h:15, from src/core/ngx_core.h:85, from src/event/ngx_event_openssl.c:9: /usr/local/include/openssl/rsa.h:193:1: note: declared here DEPRECATEDIN_0_9_8(RSA *RSA_generate_key(int bits, unsigned long e, void ^ src/event/ngx_event_openssl.c: In function ‘ngx_ssl_dhparam’: src/event/ngx_event_openssl.c:943:11: error: dereferencing pointer to incomplete type ‘DH {aka struct dh_st}’ dh->p = BN_bin2bn(dh1024_p, sizeof(dh1024_p), NULL); ^ src/event/ngx_event_openssl.c: In function ‘ngx_ssl_handshake’: src/event/ngx_event_openssl.c:1166:31: error: dereferencing pointer to incomplete type ‘SSL {aka struct ssl_st}’ if (c->ssl->connection->s3) { ^ src/event/ngx_event_openssl.c: In function ‘ngx_ssl_connection_error’: src/event/ngx_event_openssl.c:1928:21: error: ‘SSL_R_NO_CIPHERS_PASSED’ undeclared (first use in this function) || n == SSL_R_NO_CIPHERS_PASSED /* 182 */ ^ src/event/ngx_event_openssl.c:1928:21: note: each undeclared identifier is reported only once for each function it appears in src/event/ngx_event_openssl.c: In function ‘ngx_ssl_session_cache’: src/event/ngx_event_openssl.c:2122:43: error: passing argument 2 of ‘SSL_CTX_sess_set_get_cb’ from incompatible pointer type [-Werror=incompatible-pointer-types] SSL_CTX_sess_set_get_cb(ssl->ctx, ngx_ssl_get_cached_session); ^ In file included from src/event/ngx_event_openssl.h:15:0, from src/core/ngx_core.h:85, from src/event/ngx_event_openssl.c:9: /usr/local/include/openssl/ssl.h:637:6: note: expected ‘SSL_SESSION * (*)(struct ssl_st *, const unsigned char *, int, int *) {aka struct ssl_session_st * (*)(struct ssl_st *, const unsigned char *, int, int *)}’ but argument is of type ‘SSL_SESSION * (*)(SSL *, u_char *, int, int *) {aka struct ssl_session_st * (*)(struct ssl_st *, unsigned char *, int, int *)}’ void SSL_CTX_sess_set_get_cb(SSL_CTX *ctx, ^ src/event/ngx_event_openssl.c: In function ‘ngx_ssl_session_id_context’: src/event/ngx_event_openssl.c:2144:27: error: storage size of ‘md’ isn’t known EVP_MD_CTX md; ^ src/event/ngx_event_openssl.c:2210:5: error: implicit declaration of function ‘EVP_MD_CTX_cleanup’ [-Werror=implicit-function-declaration] EVP_MD_CTX_cleanup(&md); ^ src/event/ngx_event_openssl.c: In function ‘ngx_ssl_session_ticket_key_callback’: src/event/ngx_event_openssl.c:2872:9: error: ‘RAND_pseudo_bytes’ is deprecated [-Werror=deprecated-declarations] RAND_pseudo_bytes(iv, 16); ^ In file included from /usr/local/include/openssl/engine.h:19:0, from src/event/ngx_event_openssl.h:22, from src/core/ngx_core.h:85, from src/event/ngx_event_openssl.c:9: /usr/local/include/openssl/rand.h:47:1: note: declared here DEPRECATEDIN_1_1_0(int RAND_pseudo_bytes(unsigned char *buf, int num)) ^ cc1: all warnings being treated as errors objs/Makefile:827: recipe for target 'objs/src/event/ngx_event_openssl.o' failed make[1]: *** [objs/src/event/ngx_event_openssl.o] Error 1 make[1]: Leaving directory '/home/hvm/桌面/Lib/tengine-tengine-2.2.0' Makefile:15: recipe for target 'install' failed make: *** [install] Error 2

php 5 pdo_odbc在macOS High Sierra上构建错误

<div class="post-text" itemprop="text"> <p>I need the pdo_odbc.so extension for php 5.6.24, running on macOS High Sierra. The webserver with php is running perfect. But without the PDO_ODBC extension yet. So I had to build the .so file....</p> <p>I installed brew (version 1.8.0), autoconf (version 2.69), unixodbc (version 2.3.7) and downloaded the php-5.6.24 ressources. After extracting the php sources, I changed to php-5.6.24/ext/pdo_odbc directory and executed:</p> <pre><code>phpize ./configure --with-pdo-odbc=unixODBC </code></pre> <p>Configure finished with the "config.status: creating config.h" message. Fine!</p> <p>Next step:</p> <pre><code>make </code></pre> <p>Make brings a lot of warnings and errors I don't understand:</p> <pre><code>admins-Mac-mini:pdo_odbc admin$ make /bin/sh /Users/admin/Downloads/php-5.6.24/ext/pdo_odbc/libtool --mode=compile cc -I/usr/include/php/ext -I/usr/local/include -DPDO_ODBC_TYPE=\"unixODBC\" -I. -I/Users/admin/Downloads/php-5.6.24/ext/pdo_odbc -DPHP_ATOM_INC -I/Users/admin/Downloads/php-5.6.24/ext/pdo_odbc/include -I/Users/admin/Downloads/php-5.6.24/ext/pdo_odbc/main -I/Users/admin/Downloads/php-5.6.24/ext/pdo_odbc -I/usr/include/php -I/usr/include/php/main -I/usr/include/php/TSRM -I/usr/include/php/Zend -I/usr/include/php/ext -I/usr/include/php/ext/date/lib -DHAVE_CONFIG_H -g -O2 -c /Users/admin/Downloads/php-5.6.24/ext/pdo_odbc/pdo_odbc.c -o pdo_odbc.lo mkdir .libs cc -I/usr/include/php/ext -I/usr/local/include -DPDO_ODBC_TYPE=\"unixODBC\" -I. -I/Users/admin/Downloads/php-5.6.24/ext/pdo_odbc -DPHP_ATOM_INC -I/Users/admin/Downloads/php-5.6.24/ext/pdo_odbc/include -I/Users/admin/Downloads/php-5.6.24/ext/pdo_odbc/main -I/Users/admin/Downloads/php-5.6.24/ext/pdo_odbc -I/usr/include/php -I/usr/include/php/main -I/usr/include/php/TSRM -I/usr/include/php/Zend -I/usr/include/php/ext -I/usr/include/php/ext/date/lib -DHAVE_CONFIG_H -g -O2 -c /Users/admin/Downloads/php-5.6.24/ext/pdo_odbc/pdo_odbc.c -fno-common -DPIC -o .libs/pdo_odbc.o /Users/admin/Downloads/php-5.6.24/ext/pdo_odbc/pdo_odbc.c:135:63: warning: cast to 'void *' from smaller integer type 'SQLUINTEGER' (aka 'unsigned int') [-Wint-to-void-pointer-cast] SQLSetEnvAttr(SQL_NULL_HANDLE, SQL_ATTR_CONNECTION_POOLING, (void*)pdo_odbc_pool_on, 0); ^ 1 warning generated. /bin/sh /Users/admin/Downloads/php-5.6.24/ext/pdo_odbc/libtool --mode=compile cc -I/usr/include/php/ext -I/usr/local/include -DPDO_ODBC_TYPE=\"unixODBC\" -I. -I/Users/admin/Downloads/php-5.6.24/ext/pdo_odbc -DPHP_ATOM_INC -I/Users/admin/Downloads/php-5.6.24/ext/pdo_odbc/include -I/Users/admin/Downloads/php-5.6.24/ext/pdo_odbc/main -I/Users/admin/Downloads/php-5.6.24/ext/pdo_odbc -I/usr/include/php -I/usr/include/php/main -I/usr/include/php/TSRM -I/usr/include/php/Zend -I/usr/include/php/ext -I/usr/include/php/ext/date/lib -DHAVE_CONFIG_H -g -O2 -c /Users/admin/Downloads/php-5.6.24/ext/pdo_odbc/odbc_driver.c -o odbc_driver.lo cc -I/usr/include/php/ext -I/usr/local/include -DPDO_ODBC_TYPE=\"unixODBC\" -I. -I/Users/admin/Downloads/php-5.6.24/ext/pdo_odbc -DPHP_ATOM_INC -I/Users/admin/Downloads/php-5.6.24/ext/pdo_odbc/include -I/Users/admin/Downloads/php-5.6.24/ext/pdo_odbc/main -I/Users/admin/Downloads/php-5.6.24/ext/pdo_odbc -I/usr/include/php -I/usr/include/php/main -I/usr/include/php/TSRM -I/usr/include/php/Zend -I/usr/include/php/ext -I/usr/include/php/ext/date/lib -DHAVE_CONFIG_H -g -O2 -c /Users/admin/Downloads/php-5.6.24/ext/pdo_odbc/odbc_driver.c -fno-common -DPIC -o .libs/odbc_driver.o /Users/admin/Downloads/php-5.6.24/ext/pdo_odbc/odbc_driver.c:52:39: error: too many arguments to function call, expected 2, have 3 add_next_index_string(info, message, 0); ~~~~~~~~~~~~~~~~~~~~~ ^ /usr/include/php/Zend/zend_API.h:437:1: note: 'add_next_index_string' declared here ZEND_API int add_next_index_string(zval *arg, const char *str); ^ /usr/include/php/main/php_config.h:6:19: note: expanded from macro 'ZEND_API' # define ZEND_API __attribute__ ((visibility("default"))) ^ /Users/admin/Downloads/php-5.6.24/ext/pdo_odbc/odbc_driver.c:53:49: error: too many arguments to function call, expected 2, have 3 add_next_index_string(info, einfo-&gt;last_state, 1); ~~~~~~~~~~~~~~~~~~~~~ ^ /usr/include/php/Zend/zend_API.h:437:1: note: 'add_next_index_string' declared here ZEND_API int add_next_index_string(zval *arg, const char *str); ^ /usr/include/php/main/php_config.h:6:19: note: expanded from macro 'ZEND_API' # define ZEND_API __attribute__ ((visibility("default"))) ^ /Users/admin/Downloads/php-5.6.24/ext/pdo_odbc/odbc_driver.c:92:41: warning: passing 'char [6]' to parameter of type 'SQLCHAR *' (aka 'unsigned char *') converts between pointers to integer types with different sign [-Wpointer-sign] rc = SQLGetDiagRec(htype, eh, recno++, einfo-&gt;last_state, &amp;einfo-&gt;last_error, ^~~~~~~~~~~~~~~~~ /usr/local/include/sql.h:727:70: note: passing argument to parameter 'Sqlstate' here SQLSMALLINT RecNumber, SQLCHAR *Sqlstate, ^ /Users/admin/Downloads/php-5.6.24/ext/pdo_odbc/odbc_driver.c:93:4: warning: passing 'char [512]' to parameter of type 'SQLCHAR *' (aka 'unsigned char *') converts between pointers to integer types with different sign [-Wpointer-sign] einfo-&gt;last_err_msg, sizeof(einfo-&gt;last_err_msg)-1, &amp;errmsgsize); ^~~~~~~~~~~~~~~~~~~ /usr/local/include/sql.h:728:72: note: passing argument to parameter 'MessageText' here SQLINTEGER *NativeError, SQLCHAR *MessageText, ^ /Users/admin/Downloads/php-5.6.24/ext/pdo_odbc/odbc_driver.c:120:42: warning: passing 'char [6]' to parameter of type 'SQLCHAR *' (aka 'unsigned char *') converts between pointers to integer types with different sign [-Wpointer-sign] rc = SQLGetDiagRec(htype, eh, recno++, discard_state, &amp;code, ^~~~~~~~~~~~~ /usr/local/include/sql.h:727:70: note: passing argument to parameter 'Sqlstate' here SQLSMALLINT RecNumber, SQLCHAR *Sqlstate, ^ /Users/admin/Downloads/php-5.6.24/ext/pdo_odbc/odbc_driver.c:121:5: warning: passing 'char [1024]' to parameter of type 'SQLCHAR *' (aka 'unsigned char *') converts between pointers to integer types with different sign [-Wpointer-sign] discard_buf, sizeof(discard_buf)-1, &amp;errmsgsize); ^~~~~~~~~~~ /usr/local/include/sql.h:728:72: note: passing argument to parameter 'MessageText' here SQLINTEGER *NativeError, SQLCHAR *MessageText, ^ /Users/admin/Downloads/php-5.6.24/ext/pdo_odbc/odbc_driver.c:161:59: warning: incompatible pointer types passing 'int *' to parameter of type 'size_t *' (aka 'unsigned long *') [-Wincompatible-pointer-types] ret = pdo_parse_params(stmt, (char*)sql, sql_len, &amp;nsql, &amp;nsql_len TSRMLS_CC); ^~~~~~~~~ /usr/include/php/ext/pdo/php_pdo_driver.h:679:27: note: passing argument to parameter 'outquery_len' here char **outquery, size_t *outquery_len); ^ /Users/admin/Downloads/php-5.6.24/ext/pdo_odbc/odbc_driver.c:197:27: warning: passing 'char *' to parameter of type 'SQLCHAR *' (aka 'unsigned char *') converts between pointers to integer types with different sign [-Wpointer-sign] rc = SQLPrepare(S-&gt;stmt, (char*)sql, SQL_NTS); ^~~~~~~~~~ /usr/local/include/sql.h:762:44: note: passing argument to parameter 'StatementText' here SQLCHAR *StatementText, SQLINTEGER TextLength); ^ /Users/admin/Downloads/php-5.6.24/ext/pdo_odbc/odbc_driver.c:236:27: warning: passing 'char *' to parameter of type 'SQLCHAR *' (aka 'unsigned char *') converts between pointers to integer types with different sign [-Wpointer-sign] rc = SQLExecDirect(stmt, (char *)sql, sql_len); ^~~~~~~~~~~ /usr/local/include/sql.h:668:47: note: passing argument to parameter 'StatementText' here SQLCHAR *StatementText, SQLINTEGER TextLength); ^ /Users/admin/Downloads/php-5.6.24/ext/pdo_odbc/odbc_driver.c:359:44: error: too many arguments provided to function-like macro invocation ZVAL_STRING(val, "ODBC-" PDO_ODBC_TYPE, 1); ^ /usr/include/php/Zend/zend_API.h:583:9: note: macro 'ZVAL_STRING' defined here #define ZVAL_STRING(z, s) do { \ ^ /Users/admin/Downloads/php-5.6.24/ext/pdo_odbc/odbc_driver.c:359:4: error: use of undeclared identifier 'ZVAL_STRING' ZVAL_STRING(val, "ODBC-" PDO_ODBC_TYPE, 1); ^ /Users/admin/Downloads/php-5.6.24/ext/pdo_odbc/odbc_driver.c:378:2: warning: incompatible pointer types initializing 'pdo_dbh_prepare_func' (aka 'int (*)(struct _pdo_dbh_t *, const char *, unsigned long, struct _pdo_stmt_t *, struct _zval_struct *)') with an expression of type 'int (pdo_dbh_t *, const char *, long, pdo_stmt_t *, zval *)' (aka 'int (struct _pdo_dbh_t *, const char *, long, struct _pdo_stmt_t *, struct _zval_struct *)') [-Wincompatible-pointer-types] odbc_handle_preparer, ^~~~~~~~~~~~~~~~~~~~ /Users/admin/Downloads/php-5.6.24/ext/pdo_odbc/odbc_driver.c:379:2: warning: incompatible pointer types initializing 'pdo_dbh_do_func' (aka 'long long (*)(struct _pdo_dbh_t *, const char *, unsigned long)') with an expression of type 'long (pdo_dbh_t *, const char *, long)' (aka 'long (struct _pdo_dbh_t *, const char *, long)') [-Wincompatible-pointer-types] odbc_handle_doer, ^~~~~~~~~~~~~~~~ /Users/admin/Downloads/php-5.6.24/ext/pdo_odbc/odbc_driver.c:380:2: warning: incompatible pointer types initializing 'pdo_dbh_quote_func' (aka 'int (*)(struct _pdo_dbh_t *, const char *, unsigned long, char **, unsigned long *, enum pdo_param_type)') with an expression of type 'int (pdo_dbh_t *, const char *, int, char **, int *, enum pdo_param_type)' (aka 'int (struct _pdo_dbh_t *, const char *, int, char **, int *, enum pdo_param_type)') [-Wincompatible-pointer-types] odbc_handle_quoter, ^~~~~~~~~~~~~~~~~~ /Users/admin/Downloads/php-5.6.24/ext/pdo_odbc/odbc_driver.c:384:2: warning: incompatible pointer types initializing 'pdo_dbh_set_attr_func' (aka 'int (*)(struct _pdo_dbh_t *, long long, struct _zval_struct *)') with an expression of type 'int (pdo_dbh_t *, long, zval *)' (aka 'int (struct _pdo_dbh_t *, long, struct _zval_struct *)') [-Wincompatible-pointer-types] odbc_handle_set_attr, ^~~~~~~~~~~~~~~~~~~~ /Users/admin/Downloads/php-5.6.24/ext/pdo_odbc/odbc_driver.c:387:2: warning: incompatible pointer types initializing 'pdo_dbh_get_attr_func' (aka 'int (*)(struct _pdo_dbh_t *, long long, struct _zval_struct *)') with an expression of type 'int (pdo_dbh_t *, long, zval *)' (aka 'int (struct _pdo_dbh_t *, long, struct _zval_struct *)') [-Wincompatible-pointer-types] odbc_handle_get_attr, /* get attr */ ^~~~~~~~~~~~~~~~~~~~ /Users/admin/Downloads/php-5.6.24/ext/pdo_odbc/odbc_driver.c:412:49: warning: cast to 'void *' from smaller integer type 'SQLUINTEGER' (aka 'unsigned int') [-Wint-to-void-pointer-cast] rc = SQLSetEnvAttr(H-&gt;env, SQL_ATTR_CP_MATCH, (void*)pdo_odbc_pool_mode, 0); ^ /Users/admin/Downloads/php-5.6.24/ext/pdo_odbc/odbc_driver.c:435:51: warning: cast to 'void *' from smaller integer type 'SQLUINTEGER' (aka 'unsigned int') [-Wint-to-void-pointer-cast] rc = SQLSetConnectAttr(H-&gt;dbc, SQL_ODBC_CURSORS, (void*)cursor_lib, SQL_IS_INTEGER); ^ /Users/admin/Downloads/php-5.6.24/ext/pdo_odbc/odbc_driver.c:456:39: warning: passing 'char *' to parameter of type 'SQLCHAR *' (aka 'unsigned char *') converts between pointers to integer types with different sign [-Wpointer-sign] rc = SQLDriverConnect(H-&gt;dbc, NULL, (char*)dbh-&gt;data_source, strlen(dbh-&gt;data_source), ^~~~~~~~~~~~~~~~~~~~~~~ /usr/local/include/sqlext.h:1793:18: note: passing argument to parameter 'szConnStrIn' here SQLCHAR *szConnStrIn, ^ /Users/admin/Downloads/php-5.6.24/ext/pdo_odbc/odbc_driver.c:457:5: warning: passing 'char [1024]' to parameter of type 'SQLCHAR *' (aka 'unsigned char *') converts between pointers to integer types with different sign [-Wpointer-sign] dsnbuf, sizeof(dsnbuf)-1, &amp;dsnbuflen, SQL_DRIVER_NOPROMPT); ^~~~~~ /usr/local/include/sqlext.h:1795:24: note: passing argument to parameter 'szConnStrOut' here SQLCHAR *szConnStrOut, ^ /Users/admin/Downloads/php-5.6.24/ext/pdo_odbc/odbc_driver.c:460:27: warning: passing 'char *' to parameter of type 'SQLCHAR *' (aka 'unsigned char *') converts between pointers to integer types with different sign [-Wpointer-sign] rc = SQLConnect(H-&gt;dbc, (char*)dbh-&gt;data_source, SQL_NTS, dbh-&gt;username, SQL_NTS, dbh-&gt;password, SQL_NTS); ^~~~~~~~~~~~~~~~~~~~~~~ /usr/local/include/sql.h:633:44: note: passing argument to parameter 'ServerName' here SQLCHAR *ServerName, SQLSMALLINT NameLength1, ^ /Users/admin/Downloads/php-5.6.24/ext/pdo_odbc/odbc_driver.c:460:61: warning: passing 'char *' to parameter of type 'SQLCHAR *' (aka 'unsigned char *') converts between pointers to integer types with different sign [-Wpointer-sign] rc = SQLConnect(H-&gt;dbc, (char*)dbh-&gt;data_source, SQL_NTS, dbh-&gt;username, SQL_NTS, dbh-&gt;password, SQL_NTS); ^~~~~~~~~~~~~ /usr/local/include/sql.h:634:44: note: passing argument to parameter 'UserName' here SQLCHAR *UserName, SQLSMALLINT NameLength2, ^ /Users/admin/Downloads/php-5.6.24/ext/pdo_odbc/odbc_driver.c:460:85: warning: passing 'char *' to parameter of type 'SQLCHAR *' (aka 'unsigned char *') converts between pointers to integer types with different sign [-Wpointer-sign] rc = SQLConnect(H-&gt;dbc, (char*)dbh-&gt;data_source, SQL_NTS, dbh-&gt;username, SQL_NTS, dbh-&gt;password, SQL_NTS); ^~~~~~~~~~~~~ /usr/local/include/sql.h:635:44: note: passing argument to parameter 'Authentication' here SQLCHAR *Authentication, SQLSMALLINT NameLength3); ^ 19 warnings and 4 errors generated. make: *** [odbc_driver.lo] Error 1 </code></pre> <p>I tried different php Version (including PHP 7..). I also tried a different phpize Version (PHP Api Version 20131106).</p> <p>What did I miss?</p> </div>

无法编译memcached php扩展

<div class="post-text" itemprop="text"> <p>I've been looking for days to compile php memcached, (not memcache), and there is absolutely no way to make it compile. I've already tried a lot of versiosn of libmemcached, memcached extension, specifying the directory for libmemcached in the ./configure line, nothing works.</p> <p>Any idea? I'm running under Ubuntu 11.10</p> <pre><code>/home/memcached-1.0.2/php_memcached.c:168:1: warning: useless storage class specifier in empty declaration [enabled by default] /home/memcached-1.0.2/php_memcached.c: In function 'php_memc_get_impl': /home/memcached-1.0.2/php_memcached.c:382:3: warning: passing argument 4 of 'memcached_mget_by_key' from incompatible pointer type [enabled by default] /usr/local/include/libmemcached-1.0/get.h:68:20: note: expected 'const char * const*' but argument is of type 'char **' /home/memcached-1.0.2/php_memcached.c:419:15: warning: assignment discards 'const' qualifier from pointer target type [enabled by default] /home/memcached-1.0.2/php_memcached.c:451:3: warning: passing argument 4 of 'memcached_mget_by_key' from incompatible pointer type [enabled by default] /usr/local/include/libmemcached-1.0/get.h:68:20: note: expected 'const char * const*' but argument is of type 'char **' /home/memcached-1.0.2/php_memcached.c: In function 'php_memc_getMulti_impl': /home/memcached-1.0.2/php_memcached.c:588:2: warning: passing argument 4 of 'memcached_mget_by_key' from incompatible pointer type [enabled by default] /usr/local/include/libmemcached-1.0/get.h:68:20: note: expected 'const char * const*' but argument is of type 'char **' /home/memcached-1.0.2/php_memcached.c:618:15: warning: assignment discards 'const' qualifier from pointer target type [enabled by default] /home/memcached-1.0.2/php_memcached.c:621:15: warning: assignment discards 'const' qualifier from pointer target type [enabled by default] /home/memcached-1.0.2/php_memcached.c: In function 'php_memc_getDelayed_impl': /home/memcached-1.0.2/php_memcached.c:737:2: warning: passing argument 4 of 'memcached_mget_by_key' from incompatible pointer type [enabled by default]/usr/local/include/libmemcached-1.0/get.h:68:20: note: expected 'const char * const*' but argument is of type 'char **' /home/memcached-1.0.2/php_memcached.c: In function 'zim_Memcached_fetch': /home/memcached-1.0.2/php_memcached.c:812:14: warning: assignment discards 'const' qualifier from pointer target type [enabled by default] /home/memcached-1.0.2/php_memcached.c:815:14: warning: assignment discards 'const' qualifier from pointer target type [enabled by default] /home/memcached-1.0.2/php_memcached.c: In function 'zim_Memcached_fetchAll': /home/memcached-1.0.2/php_memcached.c:863:15: warning: assignment discards 'const' qualifier from pointer target type [enabled by default] /home/memcached-1.0.2/php_memcached.c:866:15: warning: assignment discards 'const' qualifier from pointer target type [enabled by default] /home/memcached-1.0.2/php_memcached.c: In function 'zim_Memcached_getServerList': /home/memcached-1.0.2/php_memcached.c:1500:15: warning: assignment from incompatible pointer type [enabled by default] /home/memcached-1.0.2/php_memcached.c: In function 'zim_Memcached_getServerByKey': /home/memcached-1.0.2/php_memcached.c:1530:9: warning: assignment discards 'const' qualifier from pointer target type [enabled by default] /home/memcached-1.0.2/php_memcached.c: In function 'zim_Memcached_getStats': /home/memcached-1.0.2/php_memcached.c:1569:15: warning: assignment from incompatible pointer type [enabled by default] /home/memcached-1.0.2/php_memcached.c: In function 'zim_Memcached_getVersion': /home/memcached-1.0.2/php_memcached.c:1604:15: warning: assignment from incompatible pointer type [enabled by default] /home/memcached-1.0.2/php_memcached.c: In function 'php_memc_new': /home/memcached-1.0.2/php_memcached.c:1865:45: error: 'zend_class_entry' has no member named 'default_properties' /home/memcached-1.0.2/php_memcached.c: In function 'php_memc_do_serverlist_callback': /home/memcached-1.0.2/php_memcached.c:1892:2: warning: passing argument 4 of 'add_assoc_string_ex' discards 'const' qualifier from pointer target type [enabled by default]/usr/local/include/php/Zend/zend_API.h:374:14: note: expected 'char *' but argument is of type 'const char *' /home/memcached-1.0.2/php_memcached.c: In function 'php_memc_zval_from_payload': /home/memcached-1.0.2/php_memcached.c:2164:4: warning: assignment from incompatible pointer type [enabled by default] /home/memcached-1.0.2/php_memcached.c: In function 'php_memc_do_result_callback': /home/memcached-1.0.2/php_memcached.c:2359:14: warning: assignment discards 'const' qualifier from pointer target type [enabled by default] /home/memcached-1.0.2/php_memcached.c:2362:14: warning: assignment discards 'const' qualifier from pointer target type [enabled by default] make: *** [php_memcached.lo] Error 1 </code></pre> </div>

Ubuntu 16 64位安装gcc4.4.0 make失败,求大神解救

../.././gcc/gimple.h:67:54: warning: ISO C does not support ‘__FUNCTION__’ predefined identifier [-Wpedantic] gimple_check_failed (__gs, __FILE__, __LINE__, __FUNCTION__, \ ^ ../.././gcc/gimple.h:4280:3: note: in expansion of macro ‘GIMPLE_CHECK’ GIMPLE_CHECK (gs, GIMPLE_PREDICT); ^ ../.././gcc/gimple.h:68:17: warning: enum conversion when passing argument 6 of ‘gimple_check_failed’ is invalid in C++ [-Wc++-compat] (CODE), 0); \ ^ ../.././gcc/gimple.h:4280:3: note: in expansion of macro ‘GIMPLE_CHECK’ GIMPLE_CHECK (gs, GIMPLE_PREDICT); ^ ../.././gcc/gimple.h:59:13: note: expected ‘enum tree_code’ but argument is of type ‘int’ extern void gimple_check_failed (const_gimple, const char *, int, \ ^ ../.././gcc/toplev.c: At top level: ../.././gcc/toplev.c:536:1: error: redefinition of ‘floor_log2’ floor_log2 (unsigned HOST_WIDE_INT x) ^ In file included from ../.././gcc/toplev.c:58:0: ../.././gcc/toplev.h:190:1: note: previous definition of ‘floor_log2’ was here floor_log2 (unsigned HOST_WIDE_INT x) ^ ../.././gcc/toplev.c:571:1: error: redefinition of ‘exact_log2’ exact_log2 (unsigned HOST_WIDE_INT x) ^ In file included from ../.././gcc/toplev.c:58:0: ../.././gcc/toplev.h:196:1: note: previous definition of ‘exact_log2’ was here exact_log2 (unsigned HOST_WIDE_INT x) ^ ../.././gcc/toplev.c: In function ‘print_to_asm_out_file’: ../.././gcc/toplev.c:1185:7: warning: format not a string literal and no format arguments [-Wformat-security] fprintf (asm_out_file, text); ^ ../.././gcc/toplev.c: In function ‘print_to_stderr’: ../.././gcc/toplev.c:1214:7: warning: format not a string literal and no format arguments [-Wformat-security] fprintf (stderr, text); ^ Makefile:2470: recipe for target 'toplev.o' failed make[3]: *** [toplev.o] Error 1 make[3]: Leaving directory '/home/zsj/下载/related/gcc-4.4.0/host-x86_64-unknown-linux-gnu/gcc' Makefile:5144: recipe for target 'all-stage1-gcc' failed make[2]: *** [all-stage1-gcc] Error 2 make[2]: Leaving directory '/home/zsj/下载/related/gcc-4.4.0' Makefile:19883: recipe for target 'stage1-bubble' failed make[1]: *** [stage1-bubble] Error 2 make[1]: Leaving directory '/home/zsj/下载/related/gcc-4.4.0' Makefile:741: recipe for target 'all' failed make: *** [all] Error 2

Graphql查询在Apollo Client和graphql-go中出现'Unknown type Int'错误

<div class="post-text" itemprop="text"> <p>I've got a graphql server implemented with <a href="https://github.com/graphql-go" rel="nofollow noreferrer">graphql-go</a>, and I'm using Apollo on the front end. Simple queries without arguments, and mutations using input object types work fine, but for some reason passing a scalar type argument in a query returns the error:</p> <pre><code>[{"message":"Unknown type \"Int\".","locations":[{"line":1,"column":19}]}] </code></pre> <p>My use could not be simpler; on the client side, my query is:</p> <pre><code>export const GET_CLIENT = gql` query client($id: Int) { client(id: $id) { id name } }` </code></pre> <p>which is used in a component like so:</p> <pre><code>&lt;Query query={GET_CLIENT} variables={{ id: 1 }} /&gt; </code></pre> <p>which resolves to this field on the backend:</p> <pre><code>// ClientQuery takes an ID and returns one client or nil var ClientQuery = &amp;graphql.Field{ Type: ClientType, Args: graphql.FieldConfigArgument{ "id": &amp;graphql.ArgumentConfig{ Type: graphql.Int, }, }, Resolve: func(p graphql.ResolveParams) (interface{}, error) { return p.Context.Value("service").(*model.Service).FindClientByID(id) }, } </code></pre> <p>I've tried passing input objects, strings, etc. but it seems that no query arguments, scalar or otherwise are ever satisfied on the backend. I've tried both master and v0.7.5 of graphql-go. Am I missing something? Help very much appreciated, it feels weird for something this basic to be such a huge blocker.</p> </div>

将Go指针传递给Cgo

<div class="post-text" itemprop="text"> <p>I've been playing around with the GLFW bindings, and I'd like to pass a Queue structure to it, via glfw.SetUserPointer(...), </p> <p>As such, I pass a it like this:</p> <pre><code>type CircularQueue struct { Values []interface{} Front, Rear int32 Capacity int32 } func newCircularQueue(capacity int32) *CircularQueue { if capacity &lt; 1 { log.Fatal("Capacity of Circular Queue Zero or Negative") } queue := &amp;CircularQueue{Capacity: capacity} queue.Values = make([]interface{}, capacity) return queue } ... events := newCircularQueue(16) window.SetUserPointer(unsafe.Pointer(events)) </code></pre> <p>But I get a runtime error, </p> <pre><code>panic: runtime error: cgo argument has Go pointer to Go pointer </code></pre> <p>I do some digging and it seems like... and I quote:</p> <pre><code>Go code may pass a Go pointer to C provided the Go memory to which it points does not contain any Go pointers. The C code must preserve this property: it must not store any Go pointers in Go memory, even temporarily. When passing a pointer to a field in a struct, the Go memory in question is the memory occupied by the field, not the entire struct. When passing a pointer to an element in an array or slice, the Go memory in question is the entire array or the entire backing array of the slice. </code></pre> <p>But, my structure has no pointers in it, I'm confused :(</p> </div>

将io字符串转换为int Atoi无效参数

<div class="post-text" itemprop="text"> <p>I'm trying to parse a string from WebSockets connection in Go language. I'm implementing both sides of the connection, so the specification of data format is depending only on me.</p> <p>As this is a simple app (generally for learning purposes), I've come up with <code>ActionId Data</code>, where ActionId is a <code>uint8</code>. <code>BackendHandler</code> is a handler for every request in WebSocket Connection.</p> <h1>Platform information</h1> <pre><code>kuba:~$ echo {$GOARCH,$GOOS,`6g -V`} amd64 linux 6g version release.r60.3 9516 </code></pre> <p>code:</p> <pre><code>const ( // Specifies ActionId's SabPause = iota ) func BackendHandler(ws *websocket.Conn) { buf := make([]byte, 512) _, err := ws.Read(buf) if err != nil { panic(err.String()) } str := string(buf) tmp, _ := strconv.Atoi(str[:0]) data := str[2:] fmt.Println(tmp, data) switch tmp { case SabPause: // Here I get `parsing "2": invalid argument` // when passing "0 2" to websocket connection minutes, ok := strconv.Atoui(data) if ok != nil { panic(ok.String()) } PauseSab(uint8(minutes)) default: panic("Unmatched input for BackendHandler") } } </code></pre> <p>All the output: (note the Println that I used for inspecting)</p> <pre><code>0 2 panic: parsing "2": invalid argument [recovered] panic: runtime error: invalid memory address or nil pointer dereference </code></pre> <p>I couldn't find the code from which this error is launch, only where the error code is defined (dependent on platform). I'd appreciate general ideas for improving my code, but mainly I just want to solve the conversion problem.</p> <p>Is this related to my buffer -&gt; string conversion and slice-manipulation(I didn't want to use SplitAfter methods)?</p> <h2>Edit</h2> <p>This code reproduces the problem:</p> <pre><code>package main import ( "strconv" "io/ioutil" ) func main() { buf , _ := ioutil.ReadFile("input") str := string(buf) _, ok := strconv.Atoui(str[2:]) if ok != nil { panic(ok.String()) } } </code></pre> <p>The file <code>input</code> has to contain <code>0 2 </code> (depending on the file ending, it may look different on other OSes). This code can be fixed by adding the ending index for reslice, this way:</p> <pre><code>_, ok := strconv.Atoui(str[2:3]) </code></pre> </div>

c++ 编写类似于标准库中find算法的模板,非引用形参和引用形参的区别是什么

``` #include <iostream> #include <string> #include <vector> using namespace std; template<typename Init,typename T> Init find(Init begin,Init end,const T& val){ while(begin!=end){ if(val==(*begin)){ return begin; } ++begin; } return end; } //为什么前2个参数改成引用就不行了 template<typename Init,typename T> Init find_(Init &begin,Init &end,const T& val){ while(begin!=end){ if(val==(*begin)){ return begin; } ++begin; } return end; } int main(){ int arr[5] = {1,2,3,45,5}; string sarr[5] = {"b","c ","dd","ee","ff"}; vector<int> ivec(arr,arr+5); vector<string> svec(sarr,sarr+5); vector<int>::iterator it; vector<string>::iterator sit; if((it=find(ivec.begin(),ivec.end(),3))!=ivec.end()){ cout << *it << "is in the vector" << endl; }else{ cout << "not found!" << endl; } if((sit = fd_(svec.begin(),svec.end(),string("b")))!=svec.end()){ cout << "find" << endl; } else{ cout << "not find"; } } ``` #把find函数的前两个形参改成引用,会产生编译错误,为什么 ``` error: invalid initialization of non-const reference of type ‘__gnu_cxx::__normal_iterator<int*, std::vector<int> >&’ from an rvalue of type ‘std::vector<int>::iterator {aka __gnu_cxx::__normal_iterator<int*, std::vector<int> >}’ if((it=find_(ivec.begin(),ivec.end(),3))!=ivec.end()){ ^ error: in passing argument 1 of ‘Init find_(Init&, Init&, const T&) [with Init = __gnu_cxx::__normal_iterator<int*, std::vector<int> >; T = int]’ template<typename Init,typename T> Init find_(Init &begin,Init &end,const T& val){ ```

在Go中仅允许const组中的值[重复]

<div class="post-text" itemprop="text"> <div class="question-status question-originals-of-duplicate"> <p>This question already has an answer here:</p> <ul> <li> <a href="/questions/37385007/creating-a-constant-type-and-restricting-the-types-values" dir="ltr">Creating a Constant Type and Restricting the Type's Values</a> <span class="question-originals-answer-count"> 2 answers </span> </li> </ul> </div> <p>Let's say I have a function that takes as an argument an <code>int</code>. I want this function to only accept values 0, 1 or 2. And it would be great if I didn't have to check this manually and return an <code>error</code>, or handle other values from within the function, but instead check it at compile time to avoid undesirable errors.</p> <pre><code>// should only accept 0, 1 or 2 func foo(bar int) { fmt.Println(bar) } </code></pre> <p>Now in order to do this, I defined my own type and 3 constant values for it:</p> <pre><code>type MyType int const ( Zero MyType = iota One Two ) </code></pre> <p>Now I can modify my function to accept a MyType instead of an int:</p> <pre><code>func foo(bar MyType) { fmt.Println(bar) } </code></pre> <p>And I can call it with any of the three constants:</p> <pre><code>foo(Zero) // would print 0 foo(One) // would print 1 foo(Two) // would print 2 </code></pre> <p>And also, it <em>can't</em> be called with an <code>int</code> instead of a <code>MyType</code></p> <pre><code>i := 5 foo(i) // errors </code></pre> <p>It returns the following error at compile time: <code>cannot use i (type int) as type MyType in argument to foo</code>. Which is actually what I want. BUT! The function can still be called like:</p> <pre><code>foo(5) // works and prints 5 </code></pre> <p>Because it infers the type from the argument (which is MyType which is actually an int) so when passing an untyped argument it converts it automatically to MyType.</p> <p>So, is there any way to define a function that only allows one of the 3 defined constants?</p> </div>

C++对Spring类进行replace操作报错问题

在子函数中对Spring类进行操作,结果报错,代码和错误原因如下。。。 请各位大佬给小白一些帮助。。。 #include <iostream> #include <fstream> #include <sstream> #include <string.h> #include <vector> using namespace std; int analyse_line(const string& str) { string P=","; string s; int count = 0; int begin=-1; int t = 0; while((begin=str.find(P,begin+1))!=string::npos) { char i = str[begin+1]; char j = str[begin-1]; char k = '\"'; count++; if ( i == k | j == k){} else { str.replace(begin,1,"/");//出错位置 } begin=begin+P.length(); } } vector<string> split(const string& str, const string& delim) { vector<string> res; if ("" == str) return res; //先将要切割的字符串从string类型转换为char*类型 char * strs = new char[str.length() + 1]; //不要忘了 strcpy(strs, str.c_str()); char * d = new char[delim.length() + 1]; strcpy(d, delim.c_str()); char *p = strtok(strs, d); while (p) { string s = p; //分割得到的字符串转换为string类型 res.push_back(s); //存入结果数组 p = strtok(NULL, d); } return res; } int main() { ifstream fin("d.csv"); //打开文件流操作 string line; while (getline(fin, line)) //整行读取,换行符“\n”区分,遇到文件尾标志eof终止读取 { analyse_line(line); //string &replace(int p0, int n0,int n, char c); std::vector<string> res = split(line, ","); } return 0; } 错误原因:28 26 [Error] passing 'const string {aka const std::basic_string<char>}' as 'this' argument of 'std::basic_string<_CharT, _Traits, _Alloc>& std::basic_string<_CharT, _Traits, _Alloc>::replace(std::basic_string<_CharT, _Traits, _Alloc>::size_type, std::basic_string<_CharT, _Traits, _Alloc>::size_type, const _CharT*) [with _CharT = char; _Traits = std::char_traits<char>; _Alloc = std::allocator<char>; std::basic_string<_CharT, _Traits, _Alloc>::size_type = long long unsigned int]' discards qualifiers [-fpermissive]

可变参数函数导致Go中不必要的堆分配

<div class="post-text" itemprop="text"> <p>I'm currently working on some performance sensitive code in Go. At one point I have a particularly tight inner loop which does three things in succession:</p> <ol> <li><p>Obtain several pointers to data. In the event of a rare error, one or more of these pointers might be <code>nil</code>.</p></li> <li><p>Check whether this error has occurred, and log an error if it has.</p></li> <li><p>Do work with the data stored in the pointers.</p></li> </ol> <p>Shown below is a toy program with the same structure (although the pointers can never actually be nil).</p> <pre><code>package main import ( "math/rand" "fmt" ) const BigScaryNumber = 1&lt;&lt;25 func DoWork() { sum := 0 for i := 0; i &lt; BigScaryNumber; i++ { // Generate pointers. n1, n2 := rand.Intn(20), rand.Intn(20) ptr1, ptr2 := &amp;n1, &amp;n2 // Check if pointers are nil. if ptr1 == nil || ptr2 == nil { fmt.Printf("Pointers %v %v contain a nil. ", ptr1, ptr2) break } // Do work with pointer contents. sum += *ptr1 + *ptr2 } } func main() { DoWork() } </code></pre> <p>When I run this on my machine, I get the following:</p> <pre><code>$ go build alloc.go &amp;&amp; time ./alloc real 0m5.466s user 0m5.458s sys 0m0.015s </code></pre> <p>However, if I remove the print statement, I get the following:</p> <pre><code>$ go build alloc_no_print.go &amp;&amp; time ./alloc_no_print real 0m4.070s user 0m4.063s sys 0m0.008s </code></pre> <p>Since the print statement is never actually called, I investigated whether the print statement was somehow causing the pointers to be allocated on the heap instead of the stack. Running the compiler with the <code>-m</code> flag on the original program gives:</p> <pre><code>$ go build -gcflags=-m alloc.go # command-line-arguments ./alloc.go:14: moved to heap: n1 ./alloc.go:15: &amp;n1 escapes to heap ./alloc.go:14: moved to heap: n2 ./alloc.go:15: &amp;n2 escapes to heap ./alloc.go:19: DoWork ... argument does not escape </code></pre> <p>while doing this on a print statement-less program gives</p> <pre><code>$ go build -gcflags=-m alloc_no_print.go # command-line-arguments ./alloc_no_print.go:14: DoWork &amp;n1 does not escape ./alloc_no_print.go:14: DoWork &amp;n2 does not escape </code></pre> <p>confirming that even an unused <code>fmt.Printf()</code> is causing heap allocations which have a very real effect on performance. I can get the same behavior by replacing <code>fmt.Printf()</code> with a variadic function which does nothing and takes <code>*int</code>s as parameters instead of <code>interface{}</code>s:</p> <pre><code>func VarArgsError(ptrs ...*int) { panic("An error has occurred.") } </code></pre> <p>I think this behavior is because Go allocates pointers on the heap whenever they are placed in a slice (although I'm not sure that this is the actual behavior of the escape analysis routines, I don't see how it would safely be able to do otherwise).</p> <p>There are two purposes to this question: first, I want to know if my analysis of the situation is correct, since I don't really understand how Go's escape analysis works. And second, I wanted suggestions for maintaining the behavior of the original program without causing unneeded allocations. My best guess is to wrap a <code>Copy()</code> function around the pointers prior to passing them into the print statement:</p> <pre><code>fmt.Printf("Pointers %v %v contain a nil.", Copy(ptr1), Copy(ptr2)) </code></pre> <p>where <code>Copy()</code> is defined as</p> <pre><code>func Copy(ptr *int) *int { if ptr == nil { return nil } else { n := *ptr return &amp;n } } </code></pre> <p>While this gives me the same performance as the no print statement case, it's weird and not the sort of thing I want to rewrite for every variable type and then wrap around <em>all</em> of my error logging code.</p> </div>

Erlang / Golang端口示例中的缓冲区大小

<div class="post-text" itemprop="text"> <p>I have a crude Erlang-to-Golang port example, passing data from Erlang to Golang and echoing the response. </p> <p>Problem is the amount of data I can transfer seems to be limited to 2^8 bytes (see below). I thought the problem was probably on the Golang side (not creating a big enough buffer) but replacing bufio.NewReader with bufio.NewReaderSize didn't work. So am now thinking the problem is maybe on the Erlang side.</p> <p>What do I need to do to increase the buffer size / be able to echo a message larger than 2^8 bytes ?</p> <p>TIA</p> <pre><code>justin@justin-ThinkPad-X240:~/work/erlang_golang_port$ erl -pa ebin Erlang/OTP 17 [erts-6.4.1] [source] [64-bit] [smp:4:4] [async-threads:10] [kernel-poll:false] Eshell V6.4.1 (abort with ^G) 1&gt; port:start("./echo"). &lt;0.35.0&gt; 2&gt; port:ping(65000). 65000 3&gt; port:ping(66000). ** exception error: bad argument in function port:call_port/1 (port.erl, line 20) 4&gt; port:start("./echo"). &lt;0.40.0&gt; 5&gt; port:ping(66000). 65536 </code></pre> <hr> <p><strong>Go</strong></p> <pre><code>package main import ( "bufio" "os" ) const Delimiter = ' ' func main() { // reader := bufio:NewReader(os.Stdin) reader := bufio.NewReaderSize(os.Stdin, 1677216) // 2**24; bytes, _ := reader.ReadBytes(Delimiter) os.Stdout.Write(bytes[:len(bytes)-1]) } </code></pre> <hr> <p><strong>Erlang</strong></p> <pre><code>-module(port). -export([start/1, stop/0, init/1]). -export([ping/1]). -define(DELIMITER, [10]). start(ExtPrg) -&gt; spawn(?MODULE, init, [ExtPrg]). stop() -&gt; myname ! stop. ping(N) -&gt; Msg=[round(65+26*random:uniform()) || _ &lt;- lists:seq(1, N)], call_port(Msg). call_port(Msg) -&gt; myname ! {call, self(), Msg}, receive {myname, Result} -&gt; length(Result) end. init(ExtPrg) -&gt; register(myname, self()), process_flag(trap_exit, true), Port = open_port({spawn, ExtPrg}, []), loop(Port). loop(Port) -&gt; receive {call, Caller, Msg} -&gt; Port ! {self(), {command, Msg++?DELIMITER}}, receive {Port, {data, Data}} -&gt; Caller ! {myname, Data} end, loop(Port); stop -&gt; Port ! {self(), close}, receive {Port, closed} -&gt; exit(normal) end; {'EXIT', Port, _Reason} -&gt; exit(port_terminated) end. </code></pre> </div>

关于c语言中strlen函数使用

/* PRESET CODE BEGIN - NEVER TOUCH CODE BELOW */ #include <stdio.h> struct btbucode//定义结构体btbucode { int n; char pn[50]; }; struct btbucode code[]={{11, "cailiao"},{12, "caiji"},{13, "shang"},{14, "jingji"},{15, "jixin"}, {16, "shipin"},{17, "lixueyuan"},{18, "fama"},{19, "waiguoyu"},{20, "yishuchuanmei"}, {95, "gonghui"},{96,"jiaowuchu"},{97,"renshichu"},{98,"kejichu"},{99,"xiaoban"}};//定义结构体数组code并初始化 /* PRESET CODE END - NEVER TOUCH CODE ABOVE */ #include<string.h> int main() {int m,flag=0,i; scanf("%d",&m); for(i=0;i<strlen(code);i++) if(m==code[i].n) {flag=1;printf("%s\n",code[i].pn);break;} if(flag==0) printf("未找到\n"); return 0;} 我用了一个strlen函数来算结构体数组长度 但是出现错误提示 error C2664: 'strlen' : cannot convert parameter 1 from 'struct btbucode [15]' to 'const char *' Types pointed to are unrelated; conversion requires reinterpret_cast, C-style cast or function-style cast

大学四年自学走来,这些私藏的实用工具/学习网站我贡献出来了

大学四年,看课本是不可能一直看课本的了,对于学习,特别是自学,善于搜索网上的一些资源来辅助,还是非常有必要的,下面我就把这几年私藏的各种资源,网站贡献出来给你们。主要有:电子书搜索、实用工具、在线视频学习网站、非视频学习网站、软件下载、面试/求职必备网站。 注意:文中提到的所有资源,文末我都给你整理好了,你们只管拿去,如果觉得不错,转发、分享就是最大的支持了。 一、电子书搜索 对于大部分程序员...

在中国程序员是青春饭吗?

今年,我也32了 ,为了不给大家误导,咨询了猎头、圈内好友,以及年过35岁的几位老程序员……舍了老脸去揭人家伤疤……希望能给大家以帮助,记得帮我点赞哦。 目录: 你以为的人生 一次又一次的伤害 猎头界的真相 如何应对互联网行业的「中年危机」 一、你以为的人生 刚入行时,拿着傲人的工资,想着好好干,以为我们的人生是这样的: 等真到了那一天,你会发现,你的人生很可能是这样的: ...

程序员请照顾好自己,周末病魔差点一套带走我。

程序员在一个周末的时间,得了重病,差点当场去世,还好及时挽救回来了。

ArrayList源码分析(入门篇)

ArrayList源码分析 前言: 写这篇博客的主要原因是,在我上一次参加千牵科技Java实习生面试时,有被面试官问到ArrayList为什么查找的速度较快,插入和删除的速度较慢?当时我回答得不好,很大的一部分原因是因为我没有阅读过ArrayList源码,虽然最后收到Offer了,但我拒绝了,打算寒假学得再深入些再广泛些,下学期开学后再去投递其他更好的公司。为了更加深入理解ArrayList,也为

我以为我学懂了数据结构,直到看了这个导图才发现,我错了

数据结构与算法思维导图

String s = new String(" a ") 到底产生几个对象?

老生常谈的一个梗,到2020了还在争论,你们一天天的,哎哎哎,我不是针对你一个,我是说在座的各位都是人才! 上图红色的这3个箭头,对于通过new产生一个字符串(”宜春”)时,会先去常量池中查找是否已经有了”宜春”对象,如果没有则在常量池中创建一个此字符串对象,然后堆中再创建一个常量池中此”宜春”对象的拷贝对象。 也就是说准确答案是产生了一个或两个对象,如果常量池中原来没有 ”宜春” ,就是两个。...

技术大佬:我去,你写的 switch 语句也太老土了吧

昨天早上通过远程的方式 review 了两名新来同事的代码,大部分代码都写得很漂亮,严谨的同时注释也很到位,这令我非常满意。但当我看到他们当中有一个人写的 switch 语句时,还是忍不住破口大骂:“我擦,小王,你丫写的 switch 语句也太老土了吧!” 来看看小王写的代码吧,看完不要骂我装逼啊。 private static String createPlayer(PlayerTypes p...

和黑客斗争的 6 天!

互联网公司工作,很难避免不和黑客们打交道,我呆过的两家互联网公司,几乎每月每天每分钟都有黑客在公司网站上扫描。有的是寻找 Sql 注入的缺口,有的是寻找线上服务器可能存在的漏洞,大部分都...

讲一个程序员如何副业月赚三万的真实故事

loonggg读完需要3分钟速读仅需 1 分钟大家好,我是你们的校长。我之前讲过,这年头,只要肯动脑,肯行动,程序员凭借自己的技术,赚钱的方式还是有很多种的。仅仅靠在公司出卖自己的劳动时...

上班一个月,后悔当初着急入职的选择了

最近有个老铁,告诉我说,上班一个月,后悔当初着急入职现在公司了。他之前在美图做手机研发,今年美图那边今年也有一波组织优化调整,他是其中一个,在协商离职后,当时捉急找工作上班,因为有房贷供着,不能没有收入来源。所以匆忙选了一家公司,实际上是一个大型外包公司,主要派遣给其他手机厂商做外包项目。**当时承诺待遇还不错,所以就立马入职去上班了。但是后面入职后,发现薪酬待遇这块并不是HR所说那样,那个HR自...

女程序员,为什么比男程序员少???

昨天看到一档综艺节目,讨论了两个话题:(1)中国学生的数学成绩,平均下来看,会比国外好?为什么?(2)男生的数学成绩,平均下来看,会比女生好?为什么?同时,我又联想到了一个技术圈经常讨...

副业收入是我做程序媛的3倍,工作外的B面人生是怎样的?

提到“程序员”,多数人脑海里首先想到的大约是:为人木讷、薪水超高、工作枯燥…… 然而,当离开工作岗位,撕去层层标签,脱下“程序员”这身外套,有的人生动又有趣,马上展现出了完全不同的A/B面人生! 不论是简单的爱好,还是正经的副业,他们都干得同样出色。偶尔,还能和程序员的特质结合,产生奇妙的“化学反应”。 @Charlotte:平日素颜示人,周末美妆博主 大家都以为程序媛也个个不修边幅,但我们也许...

MySQL数据库面试题(2020最新版)

文章目录数据库基础知识为什么要使用数据库什么是SQL?什么是MySQL?数据库三大范式是什么mysql有关权限的表都有哪几个MySQL的binlog有有几种录入格式?分别有什么区别?数据类型mysql有哪些数据类型引擎MySQL存储引擎MyISAM与InnoDB区别MyISAM索引与InnoDB索引的区别?InnoDB引擎的4大特性存储引擎选择索引什么是索引?索引有哪些优缺点?索引使用场景(重点)...

如果你是老板,你会不会踢了这样的员工?

有个好朋友ZS,是技术总监,昨天问我:“有一个老下属,跟了我很多年,做事勤勤恳恳,主动性也很好。但随着公司的发展,他的进步速度,跟不上团队的步伐了,有点...

我入职阿里后,才知道原来简历这么写

私下里,有不少读者问我:“二哥,如何才能写出一份专业的技术简历呢?我总感觉自己写的简历太烂了,所以投了无数份,都石沉大海了。”说实话,我自己好多年没有写过简历了,但我认识的一个同行,他在阿里,给我说了一些他当年写简历的方法论,我感觉太牛逼了,实在是忍不住,就分享了出来,希望能够帮助到你。 01、简历的本质 作为简历的撰写者,你必须要搞清楚一点,简历的本质是什么,它就是为了来销售你的价值主张的。往深...

玩转springboot启动banner定义所得

最近接手了一个springboot项目,不是不熟悉这个框架,启动时打印的信息吸引了我。 这不是我熟悉的常用springboot的打印信息啊,我打开自己的项目: 还真是的,不用默认的感觉也挺高大上的。一时兴起,就去研究了一下源代码,还正是有些收获,稍后我会总结一下。正常情况下做为一个老程序员,是不会对这种小儿科感兴趣的,不就是一个控制台打印嘛。哈哈! 于是出于最初的好奇,研究了项目的源代码。看到

带了6个月的徒弟当了面试官,而身为高级工程师的我天天修Bug......

即将毕业的应届毕业生一枚,现在只拿到了两家offer,但最近听到一些消息,其中一个offer,我这个组据说客户很少,很有可能整组被裁掉。 想问大家: 如果我刚入职这个组就被裁了怎么办呢? 大家都是什么时候知道自己要被裁了的? 面试软技能指导: BQ/Project/Resume 试听内容: 除了刷题,还有哪些技能是拿到offer不可或缺的要素 如何提升面试软实力:简历, 行为面试,沟通能...

离职半年了,老东家又发 offer,回不回?

有小伙伴问松哥这个问题,他在上海某公司,在离职了几个月后,前公司的领导联系到他,希望他能够返聘回去,他很纠结要不要回去? 俗话说好马不吃回头草,但是这个小伙伴既然感到纠结了,我觉得至少说明了两个问题:1.曾经的公司还不错;2.现在的日子也不是很如意。否则应该就不会纠结了。 老实说,松哥之前也有过类似的经历,今天就来和小伙伴们聊聊回头草到底吃不吃。 首先一个基本观点,就是离职了也没必要和老东家弄的苦...

男生更看重女生的身材脸蛋,还是思想?

往往,我们看不进去大段大段的逻辑。深刻的哲理,往往短而精悍,一阵见血。问:产品经理挺漂亮的,有点心动,但不知道合不合得来。男生更看重女生的身材脸蛋,还是...

为什么程序员做外包会被瞧不起?

二哥,有个事想询问下您的意见,您觉得应届生值得去外包吗?公司虽然挺大的,中xx,但待遇感觉挺低,马上要报到,挺纠结的。

当HR压你价,说你只值7K,你该怎么回答?

当HR压你价,说你只值7K时,你可以流畅地回答,记住,是流畅,不能犹豫。 礼貌地说:“7K是吗?了解了。嗯~其实我对贵司的面试官印象很好。只不过,现在我的手头上已经有一份11K的offer。来面试,主要也是自己对贵司挺有兴趣的,所以过来看看……”(未完) 这段话主要是陪HR互诈的同时,从公司兴趣,公司职员印象上,都给予对方正面的肯定,既能提升HR的好感度,又能让谈判气氛融洽,为后面的发挥留足空间。...

面试:第十六章:Java中级开发(16k)

HashMap底层实现原理,红黑树,B+树,B树的结构原理 Spring的AOP和IOC是什么?它们常见的使用场景有哪些?Spring事务,事务的属性,传播行为,数据库隔离级别 Spring和SpringMVC,MyBatis以及SpringBoot的注解分别有哪些?SpringMVC的工作原理,SpringBoot框架的优点,MyBatis框架的优点 SpringCould组件有哪些,他们...

面试阿里p7,被按在地上摩擦,鬼知道我经历了什么?

面试阿里p7被问到的问题(当时我只知道第一个):@Conditional是做什么的?@Conditional多个条件是什么逻辑关系?条件判断在什么时候执...

终于懂了TCP和UDP协议区别

终于懂了TCP和UDP协议区别

你打算用Java 8一辈子都不打算升级到Java 14,真香

我们程序员应该抱着尝鲜、猎奇的心态,否则就容易固步自封,技术停滞不前。

无代码时代来临,程序员如何保住饭碗?

编程语言层出不穷,从最初的机器语言到如今2500种以上的高级语言,程序员们大呼“学到头秃”。程序员一边面临编程语言不断推陈出新,一边面临由于许多代码已存在,程序员编写新应用程序时存在重复“搬砖”的现象。 无代码/低代码编程应运而生。无代码/低代码是一种创建应用的方法,它可以让开发者使用最少的编码知识来快速开发应用程序。开发者通过图形界面中,可视化建模来组装和配置应用程序。这样一来,开发者直...

面试了一个 31 岁程序员,让我有所触动,30岁以上的程序员该何去何从?

最近面试了一个31岁8年经验的程序猿,让我有点感慨,大龄程序猿该何去何从。

大三实习生,字节跳动面经分享,已拿Offer

说实话,自己的算法,我一个不会,太难了吧

程序员垃圾简历长什么样?

已经连续五年参加大厂校招、社招的技术面试工作,简历看的不下于万份 这篇文章会用实例告诉你,什么是差的程序员简历! 疫情快要结束了,各个公司也都开始春招了,作为即将红遍大江南北的新晋UP主,那当然要为小伙伴们做点事(手动狗头)。 就在公众号里公开征简历,义务帮大家看,并一一点评。《启舰:春招在即,义务帮大家看看简历吧》 一石激起千层浪,三天收到两百多封简历。 花光了两个星期的所有空闲时...

《经典算法案例》01-08:如何使用质数设计扫雷(Minesweeper)游戏

我们都玩过Windows操作系统中的经典游戏扫雷(Minesweeper),如果把质数当作一颗雷,那么,表格中红色的数字哪些是雷(质数)?您能找出多少个呢?文中用列表的方式罗列了10000以内的自然数、质数(素数),6的倍数等,方便大家观察质数的分布规律及特性,以便对算法求解有指导意义。另外,判断质数是初学算法,理解算法重要性的一个非常好的案例。

《Oracle Java SE编程自学与面试指南》最佳学习路线图(2020最新版)

正确选择比瞎努力更重要!

Java岗开发3年,公司临时抽查算法,离职后这几题我记一辈子

前几天我们公司做了一件蠢事,非常非常愚蠢的事情。我原以为从学校出来之后,除了找工作有测试外,不会有任何与考试有关的事儿。 但是,天有不测风云,公司技术总监、人事总监两位大佬突然降临到我们事业线,叫上我老大,给我们组织了一场别开生面的“考试”。 那是一个风和日丽的下午,我翘着二郎腿,左手端着一杯卡布奇诺,右手抓着我的罗技鼠标,滚动着轮轴,穿梭在头条热点之间。 “淡黄的长裙~蓬松的头发...

立即提问