小编Ash*_*egi的帖子

int变量:3;

在CI中看到了这段代码:

struct stud{
int b:3;
};
Run Code Online (Sandbox Code Playgroud)

这是在gcc编译.变量b3代表什么?另外,请解释一下使用方法:.

还有这样的迹象吗?

c struct

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

对C中的scanf()感到困惑?

我在C中看到了这段代码并运行它:

int i,j;
scanf("%d %d"+scanf("%d %d",&i,&j));
printf("%d %d",i,j);
Run Code Online (Sandbox Code Playgroud)

输入:

1 2 3
Run Code Online (Sandbox Code Playgroud)

输出:

3 2
Run Code Online (Sandbox Code Playgroud)

这是非常意外的(逆序和三个输入).

请解释一下.

c scanf

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

从原始指针到std :: shared_ptr

我的项目中有这两个函数:

char* V8StringToChar(v8::Handle<v8::String> str);
char* V8StringToChar(v8::Local<v8::Value> val);
Run Code Online (Sandbox Code Playgroud)

我将它们转换为:

template <class T>
class ArrayDeleter {
public:
    void operator () (T* d) const
    { delete [] d; }
};
std::shared_ptr<char> V8StringToChar(v8::Handle<v8::String> str);
std::shared_ptr<char> V8StringToChar(v8::Local<v8::Value> val);
Run Code Online (Sandbox Code Playgroud)

与身体一样

std::shared_ptr<char> V8StringToChar(Handle<String> str) {
  int len = str->Utf8Length();
  char* buf = new char[len + 1];
  str->WriteUtf8(buf, len + 1);
  return std::shared_ptr<char>(buf, ArrayDeleter<char>());
}
std::shared_ptr<char> V8StringToChar(Local<Value> val) {
  return V8StringToChar(val->ToString());
}
Run Code Online (Sandbox Code Playgroud)

并且每次使用它们(&*V8StringToChar(whatever)).

它构建完美.

它导致运行时错误.

有没有可能失败的情况请提供一些好的解决方案?

c++ shared-ptr

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

Send 只能针对 struct/enum 类型实现,而不能针对 Trait 实现

我很难实现Send某个特质。完整代码在操场上

我有一个Storage特点:

pub trait Storage {
    fn get_value(&self, key: &str) -> Result<Vec<u8>, Error>;
    fn put_value(&mut self, key: &str, value: &[u8]) -> Result<(), Error>;
    fn key_exists(&self, key: &str) -> bool;
    fn delete_key(&mut self, key: &str) -> Result<(), Error>;
}
Run Code Online (Sandbox Code Playgroud)

它是Consistency结构的一部分:

pub struct Consistency<'a> {
    storage: &'a mut Storage,
}
Run Code Online (Sandbox Code Playgroud)

我已经实现了一个MemoryStorage结构:

#[derive(Debug)]
struct MemoryStorage {
    data: HashMap<String, Vec<u8>>,
}

impl Storage for MemoryStorage {
    fn get_value(&self, key: &str) -> Result<Vec<u8>, Error> { …
Run Code Online (Sandbox Code Playgroud)

multithreading rust

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

标签 统计

c ×2

c++ ×1

multithreading ×1

rust ×1

scanf ×1

shared-ptr ×1

struct ×1