小编use*_*849的帖子

奇怪的声明和C中函数的定义

我维护了一个非常古老的C项目(编写这些项目的程序员已经很久了)我找到了类似这样的东西:

(以开头的行//给出包含以下行的文件的名称.)

声明:

// db/stor_procs/sp_table.c
/* Special hack prototype */
int32_t put_column_value(table_t * tab, row_t * row, u_int16_t colnum, rt_value_t * v);

// db/triggers/specials.c
/* BAD HACK */
int32_t put_column_value(table_t * tab, row_t * row, u_int16_t colnum, rt_value_t * v);

// db_sean_add_alarm/src/rt_access.c
int32_t put_column_value(struct xput_info *xptr, table_t * tab, row_t * row, u_int16_t colnum, rt_value_t * v);

// db_sean_add_alarm/stor_procs/sp_table.c
/* Special hack prototype */
int32_t put_column_value(table_t * tab, row_t * row, u_int16_t colnum, rt_value_t * v);
Run Code Online (Sandbox Code Playgroud)

定义:

// …
Run Code Online (Sandbox Code Playgroud)

c

5
推荐指数
1
解决办法
163
查看次数

如何初始化boost :: process :: child(boost process 0.5)?

我想存储boost :: process的子节点,但不知道如何初始化它

操作系统:win7 64位编译器:msvc2008 32位提升:1_55_0

简化后的例子

#include <boost/process/initializers.hpp>
#include <boost/process.hpp>

#include <boost/system/system_error.hpp>

#include <iostream>

void test_boost_system()
{
    namespace bp = boost::process;
    namespace bpi = boost::process::initializers;

    //bp::child child; //#1

    boost::system::error_code ec;
    bp::child child_2 = bp::execute(bpi::run_exe("ldapInterface.exe"), bpi::set_on_error(ec));
    if(ec.value() != 0){
        std::cout<<ec.message()<<std::endl;
    }else{
        std::cout<<"success"<<std::endl;
    }    
}
Run Code Online (Sandbox Code Playgroud)

如果我不想使用execute来初始化它,我怎么能初始化它?

伪代码:

namespace bp = boost::process;
namespace bpi = boost::process::initializers; 

class process_manager
{
public:
    ~process_manager() { bp::terminate(child_); }

    void open_process(std::string const &process)
    {

       child_ = bp::execute(bpi::run_exe(process)); //compile error
    }

private:
    bp::child child_;
};
Run Code Online (Sandbox Code Playgroud)

错误消息:错误C2512:'boost :: process …

c++ boost

4
推荐指数
1
解决办法
918
查看次数

通过 cmake 禁用特定库的警告

我正在使用 boost、Qt 和其他库来开发一些应用程序并使用 cmake 作为我的 make 工具。为了更早地消除问题,我决定打开最强的警告标志(感谢mloskot

if(MSVC)
  # Force to always compile with W4
  if(CMAKE_CXX_FLAGS MATCHES "/W[0-4]")
    string(REGEX REPLACE "/W[0-4]" "/W4" CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS}")
  else()
    set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} /W4")
  endif()
elseif(CMAKE_COMPILER_IS_GNUCC OR CMAKE_COMPILER_IS_GNUCXX OR
"${CMAKE_CXX_COMPILER_ID}" STREQUAL "Clang")
  # Update if necessary
  set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -Wall -Wno-long-long -pedantic")
endif()
Run Code Online (Sandbox Code Playgroud)

到目前为止一切顺利,但这也会触发很多关于我正在使用的库的警告,是否可以通过 cmake 禁用特定文件夹、文件或库的警告?

编辑:我在谈论 3rd 方库的用法。示例是

G:\qt5\T-i386-ntvc\include\QtCore/qhash.h(81) : warning C4127: conditional expression is constant

G:\qt5\T-i386-ntvc\include\QtCore/qlist.h(521) : warning C4127: conditional expression is constant
        G:\qt5\T-i386-ntvc\include\QtCore/qlist.h(511) : while compiling class template member function 'void QList<T>::append(const …
Run Code Online (Sandbox Code Playgroud)

c++ qt boost cmake

4
推荐指数
1
解决办法
8797
查看次数

将函数转换为函数指针

typedef void (*LoopCallback)(int fd, void * arg);

LoopCallback func_ptr = 0;

void call_back(int value)
{
    printf("%d", value);
}

void sys_register_input(LoopCallback call_back)
{
    func_ptr = call_back;
}

int main()
{
    sys_register_input((LoopCallback)call_back);
    func_ptr(33, 0);
}
Run Code Online (Sandbox Code Playgroud)

在其中一个遗留项目中找到此代码,这种转换是否在c中有效?

编辑:调用函数ptr

c

2
推荐指数
1
解决办法
82
查看次数

限制变量范围的利弊

从"C++编程语言4版"一书中,作者喜欢限制变量的范围.它在"3.2.1.3初始化容器"一章中

代码是:

Vector read(istream& is)
{
    Vector v;
    for (double d; is>>d;) // read floating-point values into d
    v.push_back(d); // add d to v
    return v;
}
Run Code Online (Sandbox Code Playgroud)

他说

我使用for语句而不是更传统的while语句来将d的范围限制在循环中.

这样做有什么好处?

c++ c++11

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

关于模板替换示例的混淆

我对"The C++ programming language 4th,28.4.4"中的代码感到困惑

template<typename T>
struct get_f_result {
private:
    template<typename X>
    static auto check(X const& x) ?> decltype(f(x)); // can call f(x)
    static substitution_failure check(...); // cannot call f(x)
public:
    using type = decltype(check(std::declval<T>()));
};
Run Code Online (Sandbox Code Playgroud)

我特别困惑的部分是这一行:

static substitution_failure check(...); // cannot call f(x)
Run Code Online (Sandbox Code Playgroud)

但我记得...不能接受非豆荚类型?那怎么可能呢?

c++ variadic-functions sfinae c++11

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

标签 统计

c++ ×4

boost ×2

c ×2

c++11 ×2

cmake ×1

qt ×1

sfinae ×1

variadic-functions ×1